Go Back   MarcomCentral (PTI) and FusionPro User Communities > Software-Related Talk > The JavaScript Library

Notices

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old October 5th, 2018, 07:00 AM
jpmiller jpmiller is offline
Junior Community Member
 
Join Date: Dec 2016
Location: Jacksonville, FL
Posts: 19
Smile Loop to fill sheet with records

I am making a production worksheet that includes the number of boxes and the set range of records per box. Attached is a FP Template with JavaScript used to create the box labels along with a mock .csv file. I am thinking there is some Loop function that would do this. The idea is to fill the one sheet up to 25 boxes. Thank you for any help you can give.
Attached Files
File Type: zip file for box label.csv.zip (374.0 KB, 8 views)
File Type: pdf VDP Worksheet_formFP.pdf (497.7 KB, 11 views)
Reply With Quote
  #2  
Old October 8th, 2018, 04:28 PM
Dan Korn's Avatar
Dan Korn Dan Korn is offline
FusionPro Senior Engineer / Forum Moderator
 
Join Date: Aug 2008
Location: Chicago, IL
Posts: 4,359
Default Re: Loop to fill sheet with records

Any time I see a job with dozens (or hundreds) of frames like this (and I see it a lot), I first feel sympathy toward whomever went through the painstaking process of laying all those frames down, because (a) it was a lot of work initially, (b) it will be very hard to maintain, if you later want to change something, and (c) it's going to be slow to compose.

Then I suggest a different approach to the job, which usually is one of these two strategies:
  1. Use imposition (to put multiple records of data into multiple pages on imposed sheets); or:
  2. Make a table (to put multiple sub-records of data into rows and columns).
In this case, you are obviously making a table. Or rather, you're trying to place content into (on top of) an existing blank table in the static background PDF, but that's really not the best way to go about this, because, in addition to being painstaking to put all those frames down, you also can't easily add rows as needed (which, with the row sizes and number of records in your sample data, you do need to), let alone overflow to a new page if there are too many rows to fit, like you can with a generated table.

Anyway, this looks like it's using the same kind of "range of records per box" concept as in the job in your other thread:
http://forums.pti.com/showthread.php?t=5222

So it follows that the "loop" to aggregate the ranges into a table will be basically the same as in that other job, though while in that other job you're putting each "range" or "box" out into a separate output record, here you want to put each "range" or "box" into a row in the table. The code will also go into a regular Text rule, which returns the table markup, rather than in a callback such as OnRecordStart.

Here's what I came up with:
Code:
var recordsPerBox = 2500; // 50
var nameFieldName = "first"; //"Lname"

var table = new FPTable;
var numColumns = 10;
for (var c = 0; c < numColumns; c++)
{
    var width = 2660;
    if (c == 0)
        width = 5800;
    if (c == 1)
        width = 10900;
        
    table.AddColumn(width);
}

var data = new ExternalDataFileEx(PrimaryInputFile());
var totalRecs = data.recordCount;
var numBoxes = Math.ceil(totalRecs / recordsPerBox);

for (var boxNum = 0; boxNum <= numBoxes;boxNum++)
{
    var row = table.AddRow();

    if (boxNum == 0)
    {
        row.type = "Header";
        row.SetContents("BOX #", "RECORDS RANGE");
    }
    else
    {
        var boxStartRec = (boxNum - 1) * recordsPerBox + 1;
        var boxEndRec = Math.min(boxNum * recordsPerBox, totalRecs);

        row.Cells[0].Content = boxNum + "/" + numBoxes;
        row.Cells[1].Content = boxStartRec + "-" + boxEndRec;
    }

    for (var c = 0; c < numColumns; c++)
    {
        var cell = row.Cells[c];
        cell.HAlign = "Center";
        cell.SetBorders("Thin", "Black", "Top", "Bottom", "Left", "Right");
        cell.Margins = { Top:45, Bottom:45, Left:20, Right:20 };

        if (boxNum == 0)
        {
            cell.TextColor = "White";
            cell.ShadeColor = "Black";
            cell.ShadePct = 100;
        }
    }
}

table.ShadingColor1 = "Black";
table.ShadingPct1 = 30;
table.ShadingRepeat1 = 1;
table.ShadingColor2 = "White";
table.ShadingRepeat2 = 1;
table.ShadingType = "ByRow";

return table.MakeTags();
Just put that in a regular Text rule, and put the name of the rule in a box filled with White, on top of the table in the static background.

You can obviously tweak the columns widths and margins and such to get the exact output you want.

You could also add another header row with the rotated column names such as "FUSIONPRO COMPOSED" (note that there's no space in "FusionPro"), "FIERY COMPOSER / HOT FOLDER", etc., by setting cell.Rotation = 90 in that row. (Though in that case, you would also need to set the text frame containing the table to have no fill, and use some other empty text frames with White fill to mask out parts of the static background.)

Finally, as I noted above, you should also set up an Overflow page for when there are too many rows for the table all fit on one page.
__________________
Dan Korn
FusionPro Developer / JavaScript Guru / Forum Moderator
PTI Marketing Technologies | Printable | MarcomCentral
LinkedIn

I am a not a Support engineer, and this forum is not a substitute for Support. My participation on this forum is primarily as a fellow user (and a forum moderator). I am happy to provide help and answers to questions when I can; however, there is no guarantee that I, or anyone else on this forum, will be able to answer all questions or fix any problems. If I ask for files to clarify an issue, I might not be able to look at them personally. I am not able to answer private messages, emails, or phone calls unless they go through proper Support channels. Please direct any sales or pricing questions to your salesperson or inquiries@marcom.com.

Complex template-building questions, as well as all installation and font questions or problems, should be directed to FusionProSupport@marcom.com. Paid consulting work may be required to fulfill your template-building needs.

This is a publicly viewable forum. Please DO NOT post fonts, or other proprietary content, to this forum. Also, please DO NOT post any "live" data with real names, addresses, or any other personal, private, or confidential data.

Please include the specific versions of FusionPro, Acrobat, and your operating system in any problem reports or help requests. I recommend putting this information in your forum signature. Please also check your composition log (.msg) file for relevant error or warning messages.

Please post questions specific to the MarcomCentral Enterprise and Web-to-Print applications in the MarcomCentral forum. Click here to request access. Or contact your Business Relationship Manager (BRM/CPM) for assistance.

Please direct any questions specific to EFI's Digital StoreFront (DSF) to EFI support.

How To Ask Questions The Smart Way

The correct spellings are JavaScript, FusionPro, and MarcomCentral (each with two capital letters and no spaces). Acceptable abbreviations are JS, FP, and MC (or MCC). There is no "S" at the end of "Expression" or "Printable"! The name of the product is FusionPro, not "Fusion". "Java" is not is not the same as JavaScript.

Check out the JavaScript Guide and JavaScript Reference! FusionPro 8.0 and newer use JavaScript 1.7. Older versions use JavaScript 1.5.

return "KbwbTdsjqu!spdlt\"".replace(/./g,function(w){return String.fromCharCode(w.charCodeAt()-1)});
Reply With Quote
Reply

Tags
javascript rules

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 08:13 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) 2011, PTI Marketing Technologies™, Inc.