Jump to content

step

Registered Users - Approved
  • Posts

    962
  • Joined

Everything posted by step

  1. The code should be this: var textFrame = "CompanyPaid"; var coPaid = [ ["BEST Choice Dollars", Field("BEST Choice Dol")], ["Fueling Your Health Credit", Field("Fueling Your He")], ["******* & Dental Premium - Employer", Field("******* Dental ")], ["Worker's Compensation", Field("Workers Comp")], ["Federal & State Unemployment", Field("Federal State U")] ]; // Set tab to just under the width of the frame var tab = '"0;' + (FindTextFrame(textFrame).width - 100) + ',Right,,,;"'; // filter out empties coPaid = coPaid.filter(function(s){ return Trim(s[1])}); // add tabs to force justify the line items coPaid = coPaid.map(function(p){ return '<p br=false tabstops=' + tab + '>' + p[0] + '<t>$' + Trim(p[1]);}); // add line breaks var result = coPaid.join('<br>'); result += '<graphic file="Greenline" width=' + FindTextFrame(textFrame).width + ' height=300>'; result += '<p tabstops=' + tab + '><f name="HelveticaNeueLt Std">Total' + '<t>$' + Trim(Field("Base Pay")); return result; And make sure that you don't put a comma after the last array in the "coPaid" array: var coPaid = [ ["Compensation", Field("Compensation")], ["Overtime", Field("Overtime")], ["Commission", Field("Commission")][color="Red"],[/color] ];
  2. You don't need to add those elements to the coPaid array. In fact, adding them (the graphic specifically) would give you weird results. Namely because 'coPaid" is a multi dimensional array made up of arrays of the line item description and line item value and adding a single value (graphic) will cause an error. I'd suggest simply tacking those unique elements to the end of that array like so: var result = coPaid.join('<br>'); result += '<graphic file="path/to/color.pdf" width=' + FindTextFrame(textFrame).width + ' height=300>'; result += '<p tabstops=' + tab + '><f name="HelveticaNeueLt Std">Total' + '<t>$' + Trim(Field("Base Pay")); return result;
  3. Because of the limitations with copyfitting with tables and not being able to set a table height, you'd probably be better off scrapping the table all together. If you do that, you can have two text frames named "CompanyPaid" and "Retirement" set to the size you'd like to restrict the text to with copyfit applied to them. That way they'll never bleed into a section they don't belong in. Here's an example of how I would set up the code for the line items in the "CompanyPaid" text frame: var textFrame = "CompanyPaid"; var coPaid = [ ["BEST Choice Dollars", Field("BEST Choice Dol")], ["Fueling Your Health Credit", Field("Fueling Your He")], ["******* & Dental Premium - Employer", Field("******* Dental ")], ["Worker's Compensation", Field("Workers Comp")], ["Federal & State Unemployment", Field("Federal State U")] ]; // Set tab to just under the width of the frame var tab = '"0;' + (FindTextFrame(textFrame).width - 100) + ',Right,,,;"'; // filter out empties coPaid = coPaid.filter(function(s){ return Trim(s[1])}); // add tabs to force justify the line items coPaid = coPaid.map(function(p){ return '<p br=false tabstops=' + tab + '>' + p[0] + '<t>$' + Trim(p[1]);}); // add line breaks coPaid = coPaid.join('<br>'); return coPaid; The only real benefit to using tables here, is the border you're placing above your 'total' line. With the approach I've illustrated above, I would suggest making a PDF graphic of that color you're using and place an inline graphic above the "total" at the width of the text frame: '<graphic file="path/to/color.pdf" width=' + FindTextFrame(textFrame).width + ' height=300>'; I'm sure someone has a better suggestion but hopefully that will get you started!
  4. You can do a check to see if the chunk is going to be less than the total number of records. If it is, use the chunk size. If it isn't, you know you're at the last chunk and you should just use the total number of records instead: var chunkSize = Int(FusionPro.Composition.JobOptions["RecordsPerChunk"]); var curr = FusionPro.Composition.inputRecordNumber; var totalRecords = FusionPro.Composition.totalRecordCount; var range = curr + (chunkSize-1); if (range >= totalRecords) { range = totalRecords; } var outputName = "Output Job " + curr + "-" + range; if (FusionPro.Composition.inputRecordNumber % chunkSize == 1){ FusionPro.Composition.OpenNewOutputFile(outputName + "." + FusionPro.Composition.outputFormatExtension); } Keep in mind that "FusionPro.Composition.totalRecordCount" requires preprocessing to be done before it's accessible. If you are using an imposition then FP preprocesses already, if not you will need to force preprocessing in the OnJobStart callback: FusionPro.Composition.forcePreprocessing = true;
  5. I think you'd basically just have to name output file the current record (i.e. 1) and then add on the chunk size (i.e. 250) when you're naming the file. Where are you setting the chunk size? If it's in the code, you might do something like this: OnRecordStart var chunkSize = 250; var curr = FusionPro.Composition.inputRecordNumber; var outputName = "Output Job " + curr + "-" + (curr + (chunkSize-1)); //return outputName // Output Job 1-250; if (FusionPro.Composition.inputRecordNumber % chunkSize == 1){ FusionPro.Composition.OpenNewOutputFile(outputName + "." + FusionPro.Composition.outputFormatExtension); } If you're setting it in the the composition dialog page, you may want to try something like this: var chunkSize = Int(FusionPro.Composition.JobOptions["RecordsPerChunk"]); var curr = FusionPro.Composition.inputRecordNumber; var outputName = "Output Job " + curr + "-" + (curr + (chunkSize-1)); //return outputName // Output Job 1-250; if (FusionPro.Composition.inputRecordNumber % chunkSize == 1){ FusionPro.Composition.OpenNewOutputFile(outputName + "." + FusionPro.Composition.outputFormatExtension); }
  6. You're right, Dan. In my example I am specifying 120% of the font size and not hard-coding that all together would certainly solve my problem, but I'm really just doing that for the sake of the example. What I'm actually doing is a little more complicated than that: I have three bodies of text (a headline in 150pt, a description in 30pt, and a disclaimer in 8pt) that stacked on top of each other in a single text frame. I want the spacing between the three bodies of text to be equal (rather than a 150 pt break and a 30pt break) so I wrote a function to parse the tags and adjust the leading of the first character of the 2nd and 3rd paragraph so the spacing between them would be equal. Which works great until the text needs to be copyfitted. I'm sure there's a better way to do that. While we're on the subject of leading tags, if they aren't tagged in the paragraph tag, do I need to specify a "leading" in TextMeasure? Or will TextMeasure assume auto-leading and determine the leading from the "pointsize" tag if the 'isTagged' property is set to 'true'?
  7. I have a tagged string that specifies the font size and the leading. That string is in a text frame with CopyFit applied to it: var str = '<p br=false leading="360" quad=C><span font="Helvetica" color="Magenta" pointsize=30>string</span>'; return str; As I understand it, CopyFit applies a magnification factor to a line of text to allow it to shrink or expand to fit a text frame. I have my OnCopyFit rule set up to copy fit "leading" and "text" but it doesn't appear to apply the same factor to both. It looks like it tries to copy fit the text first and then the leading (if necessary). Is there a way to determine the magnification factor being applied for the "text" type and apply the same magnification factor to the "leading" type (as it works with auto-leading)? Theoretically: OnCopyFit if (!Copyfit(new MagnifyAttributes("text", 5, 400, 6, 672))) { ReportWarning("Could not copyfit text in flow " + FusionPro.Composition.CurrentFlow.name); } else { try { var factor = FusionPro.Composition.CurrentFlow.content.match(/factor="(\d*)"/)[1]; } catch (e){ var factor = 100; } FindTextFrame(FusionPro.Composition.CurrentFlow.name).content = '<magnify factor="' + factor + '" type="leading">' + FindTextFrame(FusionPro.Composition.CurrentFlow.name).content + '</magnify>'; } Is there a way to make use of the OnCopyFit Callback for this? Or will I need to write a function that uses TextMeasure?
  8. Thanks, Dan. I was afraid that may have been the response but that does help explain why those properties aren't accessible. Are repeatable components capable of being inserted into a table? I hadn't had much success with that and wasn't able to find much insight regarding it on the forums. Unfortunately, due to company policy, I am unable to upload my template to the forum. My repeatable component is essentially variable text placed on top of a variable graphic. I tried some trickery with adjusting superscript offset to force the text onto the graphic but I choose the repeatable component route because of the added CopyFit functionality for the variable text in each instance of the component. Using a table versus adding columns to a text frame would be nice, though.
  9. As a side note, I should mention that the 'numberOfTemplates' variable is being determined dynamically based on a function that returns the 1,2, or 3 repeatable components based on whether fields "A", "B", and "C" have values: var result = Rule("Headline"); var numberOfTemplates = (NormalizeEntities(result).match(/template/g).length)/2; . . . frame.content = result; So even though I hardcoded the value in my above example, the OnRecordStart Callback is still capable of adjusting for single, double, or triple repeatable components.
  10. Is there a way to access the properties of a Repeatable Component? Even if it's read only? Something like: var template = new FPRepeatableComponent('myTemplateName'); return template.width; I have a repeatable component that I'd like to repeat up to 3 times and center on a sheet that is 11 inches wide. In order to do this, (I assume) I'd have to build the repeatable component to the size of the component itself (11"/3 (potential components)). I can force the template to the center of a text frame by adjusting the text inset of the text frame based on how many repeatable components I have like so: (OnRecordStart) var template = new FPRepeatableComponent('myTemplateName'); var frame = FindTextFrame("My Text Frame"); var numberOfTemplates = 2; var templateSize = (3.3*7200)* numberOfTemplates; // inches var frameSize = frame.width; var indentSize = (frameSize-(templateSize))/2; frame.columns = numberOfTemplates; frame.textInsetX = indentSize; frame.content = template + template; But I'd like this rule to be a little more scalable to use with other repeatable components that aren't 3.3". Ideally I'd be able to make the edits in red: var template = new FPRepeatableComponent('myTemplateName'); var frame = FindTextFrame("My Text Frame"); var numberOfTemplates = 2; [color="Red"]var templateSize = (template.width)* numberOfTemplates; // inches [/color]var frameSize = frame.width; var indentSize = (frameSize-(templateSize))/2; frame.columns = numberOfTemplates; frame.textInsetX = indentSize; frame.content = template + template; Is this possible? Is there another way to center a repeatable component within a larger text frame? Is this a feature that is available in a later version of FP than I am currently running (8.2.7)? Any tips would be greatly appreciated!
  11. Please understand that I've not seen all of the rules in your template or your data. That being said, the code that I added to your existing code wasn't meant to be copied-and-pasted and assumed to work perfectly for your job without being tweaked. It was merely an example of how I would create a variable to hold a sum of a field. It's difficult to say why it's not working for you because I haven't seen an example of the data file you're using or your template. If you collect your template and data to upload to the forum, I (or any of the other knowledgable users) can take a look for you.
  12. Well, you have to add the return to the end of it: return returnStr;
  13. Just add a variable ("total") to hold the sum of each amount and add to it as you're stepping through the external data. My edits in red: [color="red"]var total = 0;[/color] for (recordWalker=1; recordWalker <= numRecsExtDF; recordWalker++) { //Compare the value of the CID field in the current record //we are looking at in the external data file to the value //of the CustomerID field in the main data file. if (externalDF.GetFieldValue(recordWalker, 'Constituent ID') == Field("Constituent ID")) { returnStr += externalDF.GetFieldValue(recordWalker, 'Gift Date'); returnStr += '<t>'; returnStr += externalDF.GetFieldValue(recordWalker, 'Gift Type'); returnStr += '<t>'; returnStr += externalDF.GetFieldValue(recordWalker, 'Gift Amount'); returnStr += '<t>'; returnStr += externalDF.GetFieldValue(recordWalker, 'Gift Receipt Number'); returnStr += '<t>'; returnStr += externalDF.GetFieldValue(recordWalker, 'Gift Receipt Amount'); returnStr += '<br>'; [color="red"]total += StringToNumber(externalDF.GetFieldValue(recordWalker, 'Gift Receipt Amount').replace(/[^\d\.]/g,''));[/color] } } [color="Red"]returnStr += '<t><t><t><t>$' + FormatNumber("#.00",total);[/color]
  14. Here's some code that searches for an area code pattern that matches what you've described (3 numbers within parentheses) and changes the font using span tags: var default_font = "Times"; var areaCode_font = "Arial"; var phone = "(411)123-4567"; return '<span font="' + default_font + '">' + phone.replace(/(\(\d{3}\))/,'<span font="' + areaCode_font + '">$1</span>') + '</span>';
  15. Since your leading zeros are dropping, your regular expression is failing to capture the pattern. In your replace function, you are looking for a series of 5 digits, a hyphen (optionally), followed by a series of 4 digits. You can try checking the zip code's length and adding the leading zeros back to it conditionally. Basically, checking to see if the zip is less than 5 digits. If it is, add leading zeros until the length of the zip is 5. If it's greater than 5 digits, add leading zeros until the length is 9. At that point your current replace function should work. Here's an example: // Assign this to your FP Field var zip = '345-1234'; // Zip Code: 00345-1234 // Remove anything that's not a digit zip = zip.replace(/[^\d]/g,''); // If the zip code is less than 5 digits, add leading zeros to make its length 5 // If it's greater than 5, add leading zeros to make its length 9 var stop = (zip.length <= 5) ? 5 : 9; while (zip.length < stop){ zip = '0' + zip; } return zip.replace(/^(\d{5})-?(\d{4})$/, "$1-$2");
  16. For your scratch off ticket, I would add your prize elements to an array (image included), shuffle the elements in the array, and build a table of the prizes. I've put together an example here: /* ------------------------------------------------- // Function for shuffling array elements // + Jonas Raoni Soares Silva // @ http://jsfromhell.com/array/shuffle [v1.0] // -------------------------------------------------*/ function Shuffle(o){ for(var j, x, i = o.length; i; j = Math.floor(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x); return o; } // Table Settings var numberOfColumns = 4; var numberOfRows = 3; var columnWidth = 1; // in inches var rowHeight = 1; // in inches // Lucky Symbol Settings var luckySymbol = { path: "/Path/to/luckySymbol.pdf", // Path to lucky symbol graphic width: 0.25, // in inches height: 0.25 // in inches } // Array of prizes (3 lucky symbols, 6 $20, 1 $25, 1 $50, 1 $75) var prizes = [luckySymbol.path,luckySymbol.path,luckySymbol.path,"$20","$20","$20","$20","$20","$20","$25","$50","$75"]; // Randomly shuffle the prizes prizes = Shuffle(prizes); var rows = []; // Array to hold rows // Start building table var table = '<table columns=' + numberOfColumns + '>'; // Add column tags for the specified amount of columns for (var i=0; i<numberOfColumns; i++){ table += '<column width=' + columnWidth*7200 + '>'; } // Add cell tags for each prize prizes.forEach(function(val){rows.push('<cell><p quad="C">' + val.replace(luckySymbol.path, '<graphic file="' + luckySymbol.path + '" height=' + luckySymbol.height*7200 + ' width=' + luckySymbol.width*7200 + '>'));}); // Create the specified amount of rows for (var n=0; n<numberOfRows; n++){1 var row = rows.splice(0,numberOfColumns); table += '<row minHeight=' + rowHeight*7200 + '>' + row.join(''); } // Close table tag table += '</table>'; return table; I imagine the scratch off image would have to be printed after the table is printed (as just a static image). Anyway, I hope that helps get you started. For more information on adjusting the table properties, check out page 27 of the TagRefGuide.pdf in the FusionPro documentation.
  17. Could you explain better what you're trying to do? At first glance, it looks like you could just put those fields into an array and filter out the empty ones. Then you could join them with a pipe and replace every other pipe with a paragraph tag. But I'd need a better explanation and possibly to see the data to give you a better answer.
  18. You will probably save yourself a lot of headache if you remove that first header row from the Excel file if it's not being used. I'm not really understanding what you're attempting to achieve through that description. Are you making a table for each record out of this data? And each table is comprised of a "H" row (header) and a variable number of "L" rows? In other words, is it the "H" in the "tipo" field that indicates it's time to start a new record or is that determined elsewhere in the data? A screenshot or posting your current template could help here. You can link to the data file from the OnJobStart Callback rule, but any output you are hoping to return needs to be done so elsewhere. So you're OnJobStart Rule should be just this: Dir = new ExternalDataFile("C:\\Users\\Production Printig\\Documents\\Progetti_PTI\\Testrules\\DBMul tipleRecord.csv", ";"); Then you can create a text rule to return the content. On the subject of returning the content, you need to make sure you actually return the content. As your code stands, it's not currently returning anything. See my modifications in red: var contaRecord = Dir.recordCount; for (var recordWalker=1; recordWalker <= contaRecord; recordWalker++) { if (Dir.GetFieldValue(recordWalker, 'ID') == Field("ID")) { Final = Final + Dir.GetFieldValue(recordWalker, "name") + " " + Dir.GetFieldValue(recordWalker, "city") + " " + Dir.GetFieldValue(recordWalker, "number") + "<br><br>"; } } return [color="Red"]Final[/color];
  19. You don't have to use code for this. You could just type that line of text and insert the variable in the text frame. Then select that line, click paragraph, and "Suppress if: containing empty variables." On the other hand, if you're wanting to do it with code, you could do something like this: var donation = Trim(Field("Donation")); var result = (donation) ? "Your last gift of " + donation + " was truly appreciated, and I hope you'll consider a similar, or slightly increased, gift this year." : ""; return result;
  20. Maybe I'm misunderstanding, but it sounds like you just want to insert a blank page for the "back" of your simplex records, impose using a duplex layout, and run the whole job duplex. However, if you're wanting the simplex sheets to run simplex and the duplex sheets to run duplex, I don't think there's a way to make that happen (at least to my knowledge). At that point, I think you'd have to separate out the simplex portion of the job into one file and the duplex portion of the job into another file and then re-sort them back together and at that point I'm not really sure how much time you're saving.
  21. Lisa, if you're trying to capture separate patterns, put them inside parentheses like so: return Field ("ProductDescription").replace(/[color="Red"]([/color]DENTtips® Master[color="red"])[/color]|[color="red"]([/color]DENTtips® Master[color="red"])[/color]/g,'DENTtips<superscript>®</superscript><f name="Compatil Fact It"> Master</f>'); Also, I'm not sure if it's on purpose or not, but your code is searching for "Motion" and in your post you say you're trying to replace "Master" so I made that edit.
  22. You can use the first 5 characters like so: return Left(Field("zip"),5); You can replace the dash and anything that comes after it: return Field("zip").replace(/-.*$/,'');
  23. I set this up using the formula Dan posted (or at least I tried to). The check digit, as I determined it, doesn't match your example so I'm not sure this is going to help you at all but I figured it may at least give you a starting place or at the very least the function for converting the alpha characters to the numeric values you listed above. I'm also unsure of where the leading zero is coming from in your example from your original post so that may have something to do with why my solution is a bit off. // Initiate variables var field1 = "CON135627"; var field2 = "U14B1DDBMR"; var result = []; var checkDigit = 0; // Function to convert alphas: // A = 30 // B = 31 // Z = 55 function getAlpha(input){ var alpha = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']; var result = alpha.indexOf(input); return result + 30; } // Concatenate fields to create the barcode field var barcode = field1 + field2; // Replace alphas with numbers barcode = barcode.replace(/[a-z]/gi, function(s){return getAlpha(ToLower(s));}); // For loop to double every other number for (var i=0; i<barcode.length; i++) { if (i%2 == 1) { result.push(barcode[i]*2); } else { result.push(barcode[i]); } } // Join result of the above for loop into a string of numbers to be added together result = result.join(''); // For loop to all of the numbers together for (var n=0; n<result.length; n++){ checkDigit += Int(result[n]); } // Modulus 10 checkDigit = 10-(checkDigit%10); return field1 + " " + field2 + checkDigit;
  24. That code needs to go in an OnRecordStart callback rule. Is that where you have it?
  25. Why do you have "duplicated" turned on in your imposition if you don't want your records duplicated 3 times across the sheet?
×
×
  • Create New...