Jump to content

Multiple page for single data


Recommended Posts

I am trying to produce multiple pdf documents using a single multi page PDF and a single data file.


What I want it to do is loop through the data once for each page in the pdf and generate one pdf file for each page. I was reading it was possible to do this using an array but I have not been able to get this to work.


I am very new to java script and some of the instructions in the forum honestly go over my head.


If anyone can guide me as to the code to use or where I can get a tutorial about using array i would appreciate it.


I have attached the file and data. I am using FusionPro 9.2.31


Thank you

multi Page.zip

Link to comment
Share on other sites

One way to do this is to set all of your pages to "unused," create an array containing the names of the pages, and tell FusionPro to compose 1 record per page in the array but repeat that "record" by the number of pages in the data file. To get started, your OnJobStart rule would look like this:

// The name of your pages
pages = [

FusionPro.Composition.composeAllRecords = false;
FusionPro.Composition.endRecordNumber = pages.length;


Which essentially tells FusionPro to only compose five records (since that is the length of the "pages" array). You can edit the names of the pages in the array there, but remember: they need to match what you've named the pages in your template.


The bulk of the process happens in OnRecordStart:

var ex = new ExternalDataFileEx(PrimaryInputFile(), '\t');
FusionPro.Composition.repeatRecordCount = ex.recordCount;

var pg = pages[FusionPro.Composition.inputRecordNumber-1];
var output = GetFileName(PrimaryInputFile()).replace(/\..+$/,'') + 
             '_' + pg + '.' + FusionPro.Composition.outputFormatExtension;

if (FusionPro.Composition.repeatRecordNumber == 1)

FusionPro.Composition.SetBodyPageUsage(pg, true);

for (var i in FusionPro.Fields)
   FusionPro.Composition.AddVariable(i, ex.GetFieldValue(FusionPro.Composition.repeatRecordNumber, i));


This code imports your linked data file as an external data file. It counts the records in the external data file and assigns the value to the "repeatRecordCount" so that each page in your template will be repeated by the number of records in your data file (46).


Then the name of the page is pulled from the global "pages" array created in the OnJobStart rule. The name of the output file is also, in part, determined by the page name. The name of the output file will be {name of input file}_{name of page}.{output format}.


If it is the start of a new record – meaning the start of a new page, a new output file is opened and named appropriately using the OpenNewOutputFile function.


Finally, the correct page is activated and proper external data field values are assigned to the FusionPro.Fields object to allow the "Field" function to continue to return the correct values.


I hope this helps get you going. Let me know if you have further questions.

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...