Jump to content

Output multiple PDF's


hoover

Recommended Posts

Hi,

 

I want to make multiple pdf files based on a database field. But the hard part is that I need to rerun the datafile 3x. Let me explain.

We have 3 types of preprinted headers on paper. We need 3 different pdf's but I want FP to do this in 1 run. The value for the pdf files isn't sorted and can't be. Ex:

record1 value=1

record2 value=1

record3 value=2

record4 value=2

record5 value=3

record6 value=2

record7 value=1

record8 value=3

 

So, all the 1's must be in the same pdf. The 2's in an other and also the 3's.

1.pdf---

record1 value=1

record2 value=1

record7 value=1

2.pdf---

record3 value=2

record4 value=2

record6 value=2

3.pdf---

record5 value=3

record8 value=3

 

Thanks for any help,

Hoover

Link to comment
Share on other sites

Can you post example data? I'm thinking you would accomplish this by pulling the data in as an external data file and running a sort on it.

 

Also, I notice that you're using FusionPro 7.2. Are all of your output files going to have the same number or records? Because FP7 does not support arbitrary chunks.

Link to comment
Share on other sites

Here's something to get you started. This brings in your data file as an external data file, pushes all of the records into an array, and then sorts the array by the "AantalCheques" field (essentially reordering your data file) at the start of the job. OnJobStart:

// Initiate variables
ex = new ExternalDataFileEx("test-DB.csv",','); // Link to data file as external data file so that you can sort it
recCount = ex.recordCount; // Count the number of records in the external data file for the for loop
sorted = []; // Create an array to hold values

// Create an object for each record with properties "recNum" (to reference the original record number)
// and "aantal" to sort the records by
for (var i=1; i<= recCount; i++){
   sorted.push({recNum: i, aantal: ex.GetFieldValue(i,"AantalCheques")});
}

// Sort the array of objects by the "anntal" property 
sorted = sorted.sort(function(a,b){return a.aantal-b.aantal});

 

Then I've reassigned your field values to the values of the resorted array in an OnRecordStart call back rule:

 

if (FusionPro.Composition.isPreview) {Rule("OnJobStart");}

// Assign the new values of the sorted data to the current fields. 
// Any instance of the field in a text frame will pull in the sorted values. 
FusionPro.Composition.AddVariable("Country", ex.GetFieldValue(sorted[FusionPro.Composition.inputRecordNumber - 1].recNum,"Country"));
FusionPro.Composition.AddVariable("Language", ex.GetFieldValue(sorted[FusionPro.Composition.inputRecordNumber - 1].recNum,"Language"));
FusionPro.Composition.AddVariable("Gender", ex.GetFieldValue(sorted[FusionPro.Composition.inputRecordNumber - 1].recNum,"Gender"));
FusionPro.Composition.AddVariable("EmailQuestion", ex.GetFieldValue(sorted[FusionPro.Composition.inputRecordNumber - 1].recNum,"EmailQuestion"));
FusionPro.Composition.AddVariable("StartSaldo", ex.GetFieldValue(sorted[FusionPro.Composition.inputRecordNumber - 1].recNum,"StartSaldo"));
FusionPro.Composition.AddVariable("EndSaldo", ex.GetFieldValue(sorted[FusionPro.Composition.inputRecordNumber - 1].recNum,"EndSaldo"));
FusionPro.Composition.AddVariable("StartDate", ex.GetFieldValue(sorted[FusionPro.Composition.inputRecordNumber - 1].recNum,"StartDate"));
FusionPro.Composition.AddVariable("EndDate", ex.GetFieldValue(sorted[FusionPro.Composition.inputRecordNumber - 1].recNum,"EndDate"));
FusionPro.Composition.AddVariable("AantalCheques", ex.GetFieldValue(sorted[FusionPro.Composition.inputRecordNumber - 1].recNum,"AantalCheques"));
FusionPro.Composition.AddVariable("VALID", ex.GetFieldValue(sorted[FusionPro.Composition.inputRecordNumber - 1].recNum,"VALID"));
FusionPro.Composition.AddVariable("SEQNR", ex.GetFieldValue(sorted[FusionPro.Composition.inputRecordNumber - 1].recNum,"SEQNR"));

 

If you have your variable fields in a text field, the OnRecordStart rule will replace those fields with the sorted values. If you reference field values in other rules, you're going to need to assign the sorted values as global variables for those rules in order to pull in the correct value.

 

And since you have 4 of each, you could output in chunks of 4 and have an OnNewOutputFile call back rule that says:

FusionPro.Composition.outputFileName = ex.GetFieldValue(sorted[FusionPro.Composition.inputRecordNumber - 1].recNum,"AantalCheques") + ".pdf";

 

Like I said, hopefully this will at least get you started and you can make tweaks here and there (for example, if you wanted to arbitrarily output chunks rather than always doing chunks of 4) to get it working exactly as you want.

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.

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