Jump to content

Loop to fill sheet with records


Recommended Posts

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.

file for box label.csv.zip

VDP Worksheet_formFP.pdf

Link to comment
Share on other sites

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 © 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:



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:

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;


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");
       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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...