Jump to content

How to tweak this for multiple PDF output


dmp

Recommended Posts

Hi awesome peoples,

I used to use this for making multiple pdf's based on trays. What I'm wondering is if this can be adapted to make a pdf based on a field that is not in order in the data.

For example, I've got a mail list that will imprint a PDF using two different shells. So I have to have two separate pdfs based on shell #1 or shell #2. But I would like them to be in the correct sort/tray order.

 

In this case the field is named Signator and will have one of two people in the field.

So

1. bob

2. bob

3. mary

4. bob

5. mary

And I'd like to have two pdfs made;

1. bob

2. bob

4. bob

and

3. mary

5. mary

 

if (CurrentRecordNumber() == 1)
   PrevTrayNum = Trim(data.GetFieldValue(StartRow[0], "Tray"));
else
   PrevTrayNum = Trim(data.GetFieldValue(StartRow[CurrentRecordNumber()-2], "Tray"));
CurrentTrayNum = Trim(data.GetFieldValue(StartRow[CurrentRecordNumber()-1], "Tray"));


if (PrevTrayNum != CurrentTrayNum)
   FusionPro.Composition.outputFileName = "Test_Output_" + CurrentTrayNum + ".pdf";

 

Am I correct in thinking this code will overwrite the pdf each time the field changes from one person to the other?

So I'd only end up with:

4. bob

and

5. mary

 

Thanks and sorry If I'm not writing clearly. I'm super confused with code as it is :)

- Mike

Link to comment
Share on other sites

JavaScript Globals

names = {};

 

OnRecordStart

var fieldKey = 'Signator'; // Key to sort on

// Only compose unique fieldKeys
FusionPro.Composition.composeThisRecord = names[Field(fieldKey)] == undefined;

// Link to Primary data file as external data file (comma delimited)
var data = new ExternalDataFileEx(PrimaryInputFile(), ',');

// Get an array of fields whose fieldKey value match that of the current record
var cursor = data.SortBy(fieldKey).FindRecords(Field(fieldKey));

// Repeat this record based on the number of matches
FusionPro.Composition.repeatRecordCount = cursor.length;

// Open a new output file at the start of the record's composition
if (FusionPro.Composition.repeatRecordNumber == 1)
   FusionPro.Composition.OpenNewOutputFile('Test_Output_' + Field(fieldKey) + ".pdf");

// Flag this fieldKey as done 
if (FusionPro.Composition.repeatRecordNumber == cursor.length)
   names[Field(fieldKey)] = false;

// Remap the fields for each iteration of the repeat
for (var field in FusionPro.Fields)
   FusionPro.Composition.AddVariable(field, 
     data.GetFieldValue(cursor[FusionPro.Composition.repeatRecordNumber-1], field));

Howbowdah?

Link to comment
Share on other sites

Thanks Step!

When I put this in there, it gives me this error:

***Error*** (OnRecordStart, line 14: Error: In ExternalDataFileEx.SortBy(), no field named Signator)

 

But I have a field called Signator, I can even drop it in with the building blocks. Am I supposed to change something in particular in the code to match my data?

 

Cheers,

Mike

Link to comment
Share on other sites

Thanks Step!

When I put this in there, it gives me this error:

***Error*** (OnRecordStart, line 14: Error: In ExternalDataFileEx.SortBy(), no field named Signator)

 

But I have a field called Signator, I can even drop it in with the building blocks. Am I supposed to change something in particular in the code to match my data?

 

Cheers,

Mike

Is your data file comma-delimited? You might want to change the line creating the ExternalDataFileEx object to this:

var data = new ExternalDataFileEx(PrimaryInputFile(), FusionPro.inputFileDelimiter);

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