Jump to content

Multiple page usage to multiple pdfs


JeremyT

Recommended Posts

I am merging business cards for multiple insurance agents. Each agent gets 3 different styles of card.

 

I'd like a pdf output for each style of card for each agent that is labelled with agent_code and style of card.

 

For instance:

 

Agent1-FormA.pdf

Agent1-FormB.pdf

Agent1-FormC.pdf

 

Agent2-FormA.pdf

Agent2-FormB.pdf

Agent2-FormC.pdf

 

Agent_code is pulled from data file.

 

I've named the pages using "Page Usage" FormA, FormB and FormC.

 

Currently it outputs files like this:

"12213function GetBodyPageUsage() { [native code] }pdf"

 

It also puts all 3 styles in 1 pdf.

 

I've tried to find information on how to use "GetBodyPageUsage()" but have been unsuccessfull.

 

Thanks,

Jeremy

 

 

    var outputName = ((Field("Agent_Code")) + FusionPro.Composition.GetBodyPageUsage);
   FusionPro.Composition.OpenNewOutputFile(outputName + FusionPro.Composition.outputFormatExtension);
   Print("Changing to output file: " + outputName + FusionPro.Composition.outputFormatExtension);

Link to comment
Share on other sites

I've tried to find information on how to use "GetBodyPageUsage()" but have been unsuccessfull.
    var outputName = ((Field("Agent_Code")) + FusionPro.Composition.GetBodyPageUsage);
   FusionPro.Composition.OpenNewOutputFile(outputName + FusionPro.Composition.outputFormatExtension);
   Print("Changing to output file: " + outputName + FusionPro.Composition.outputFormatExtension);

Well, first of all, FusionPro.Composition.GetBodyPageUsage is a function, so if you want to call the function, you have to use parentheses. You also need to specify a page, the usage of which is returned. It returns a Boolean (true/false) value. It's intended to be used in something like this:

if (FusionPro.Composition.GetBodyPageUsage("FormA"))
 return "Form A is active";
else
 return "Form A is hidden";

The function is provided for completeness, as the "accessor," or "set," complement to the "mutator," or "get," function FusionPro.Composition.SetBodyPageUsage().

 

But I don't think that's what you want to do here. I'm assuming that this is the same job that was discussed in this thread. The field "form number" is pulled from the data file as well, right? So I think this is what you want:

var outputName = Field("Agent_Code") + "-" + Field("form number") +
                       "." + FusionPro.Composition.outputFormatExtension;
FusionPro.Composition.OpenNewOutputFile(outputName);
Print("Changing to output file: " + outputName);

Link to comment
Share on other sites

But I don't think that's what you want to do here. I'm assuming that this is the same job that was discussed in this thread. The field "form number" is pulled from the data file as well, right? So I think this is what you want:

var outputName = Field("Agent_Code") + "-" + Field("form number") +
                       "." + FusionPro.Composition.outputFormatExtension;
FusionPro.Composition.OpenNewOutputFile(outputName);
Print("Changing to output file: " + outputName);

 

This a different job than one you mentioned: //http://forums.pti.com/showthread.php?t=3607

 

It's similar in that I am trying to get multiple PDFs output. But this time "form number" is not in the data file. I am trying to get the "from number" from the Page Usage.

 

Again, I've got ideas on what I want to do but am unsure of how to do it. I'm still not that familiar with Javascript.

 

Thanks,

Jeremy

Link to comment
Share on other sites

Okay, then I need more explanation. What is driving the call to OpenNewOutputFile? In other words, under what conditions are you deciding to start a new output file? Presumably, there's some other code which is calling FusionPro.Composition.SetBodyPageUsage() to output specific pages to each output file. I would think you could key off of that same condition.

 

This would all be much easier if you could post the job.

Link to comment
Share on other sites

Here is the job. Right now it's very basic graphically because I am still waiting for the customer to send artwork.

 

I'd like a new output file for each page for each record. So each record would have 3 pdfs. Each pdf labelled based on page name in Page Usage.

 

I don't have anything in the data file to tell it which page to use since each record gets all pages.

 

Thanks,

Jeremy

Form ABCDEF SMIC 0121.zip

Link to comment
Share on other sites

I'd like a new output file for each page for each record. So each record would have 3 pdfs. Each pdf labelled based on page name in Page Usage.

 

I don't have anything in the data file to tell it which page to use since each record gets all pages.

Okay, we need to make sure we're on the same page (no pun intended) here about what constitutes an output page, an output record, and an output file.

 

By default, FusionPro outputs all the pages for each record. If your template PDF contains three body pages, then each record will have three pages. You can output each record to its own output file, but each of those output files will have three pages in it.

 

Now, you can get FusionPro to output only one of the three pages per record, but you need to tell it to do that by calling FusionPro.Composition.SetBodyPageUsage in OnRecordStart. So you can output, say, just Form A by doing this:

FusionPro.Composition.SetBodyPageUsage("Form A", true);
FusionPro.Composition.SetBodyPageUsage("Form B", false);
FusionPro.Composition.SetBodyPageUsage("Form C", false);

Or you can change which are set to true and false to output a different set of pages for the record.

 

Note that, once you call FusionPro.Composition.SetBodyPageUsage, you could call FusionPro.Composition.GetBodyPageUsage to return the same usage that you set for each page. But GetBodyPageUsage isn't like a per-page callback; it won't return anything different than what you specify in SetBodyPageUsage (or in the Page Usage dialog), and it, by itself, won't let you output each page to a different record.

 

You can also repeat a record, by setting FusionPro.Composition.repeatRecordCount in OnRecordStart, and you can do different things depending on which iteration of the repeat you're on, based on the FusionPro.Composition.repeatRecordNumber propery.

 

So, you could use both FusionPro.Composition.repeatRecordNumber and FusionPro.Composition.SetBodyPageUsage to accomplish what you want, something like this:

FusionPro.Composition.repeatRecordCount = 3;
var FormLetter = Chr(Asc('A') + FusionPro.Composition.repeatRecordNumber - 1);
var FormToUse = "Form " + FormLetter;

// Set all body pages to be unused initially in the Page Usage dialog.
FusionPro.Composition.SetBodyPageUsage(FormToUse, true);

var outputName = Field("Agent_Code") + "-" + FormToUse + "." + FusionPro.Composition.outputFormatExtension;
FusionPro.Composition.OpenNewOutputFile(outputName);
Print("Changing to output file: " + outputName);

However, this is not going to be very efficient, as it has to compose a lot of iterations, and it's also going to be hard to scale if you get more styles of the card, as you would have to add more pages, name them, etc.

 

If the text frame for each form is really going to be in the same place, then what I would do instead of this, is have a single blank body page, with a graphic frame the size of the entire page, and the text frame on top of that. Then instead of having to replace a template page when one of the cards change, you can have each card background be a graphic resource (in PDF or any other graphic format), and set it into the graphic frame. But this will only work if each card has the variable text in the same place.

 

If each card needs the variable text to be in a different place relative to the static background, there are still more efficient and scalable ways to set up the template than to turn the pages on and off. You could use repeatable components (Template pages) for each card, still with a single Body page, and a rule to call out the appropriate repeatable component. This is a more complicated setup, but it's more scalable if you have more card designs to bring in.

Link to comment
Share on other sites

FusionPro.Composition.repeatRecordCount = 3;
var FormLetter = Chr(Asc('A') + FusionPro.Composition.repeatRecordNumber - 1);
var FormToUse = "Form " + FormLetter;

// Set all body pages to be unused initially in the Page Usage dialog.
FusionPro.Composition.SetBodyPageUsage(FormToUse, true);

var outputName = Field("Agent_Code") + "-" + FormToUse + "." + FusionPro.Composition.outputFormatExtension;
FusionPro.Composition.OpenNewOutputFile(outputName);
Print("Changing to output file: " + outputName);

 

With my test file the code you gave works well. The variable text won't be in the same spot on each card so I'm not sure using a template would work.

 

This set up is a huge improvement over how we've been doing it now. Currently the merge is done with InDesign for each style. Then pdfs are split and then manually labelled with the Agent Code.

 

 

Looking at the real artwork, the pages will be named "G2", "G2NF", and -"BC" .

 

So when done the output pdfs will look like this:

Agent_CodeG2.pdf

Agent_CodeG2NF.pdf

Agent_Code-BC.pdf

 

How do I adjust for the new page names?

 

 

Thanks,

Jeremy

Link to comment
Share on other sites

With my test file the code you gave works well.

Great!

The variable text won't be in the same spot on each card so I'm not sure using a template would work.

That's why I suggested that you could create a page of type Template for each new card, instead of a page of type Body, where each one could have a different layout. There would still be one Body page, with a big text frame on it, and a rule to call out a specific Template (repeatable component) page per record. (Although you may be able to use the same Template page for multiple cards.) It's not necessarily much less template design work, but it's a big optimization in terms of composition time, especially as you add more and more cards (pages).

This set up is a huge improvement over how we've been doing it now. Currently the merge is done with InDesign for each style. Then pdfs are split and then manually labelled with the Agent Code.

Sure, this should be a lot better. InDesign is not a variable data composition tool, whereas FusionPro is designed to do stuff like this. With Producer API, you can do even more.

Looking at the real artwork, the pages will be named "G2", "G2NF", and -"BC" .

 

So when done the output pdfs will look like this:

Agent_CodeG2.pdf

Agent_CodeG2NF.pdf

Agent_Code-BC.pdf

 

How do I adjust for the new page names?

You can create an array of names, and call them out by the record repeat number. Also, you can pass the page number to FusionPro.Composition.SetBodyPageUsage, instead of a name, so you don't even have to rename the pages in the template. Try this:

// Set all body pages to be unused initially in the Page Usage dialog.
FusionPro.Composition.SetBodyPageUsage(FusionPro.Composition.repeatRecordNumber, true);

var formNames = [ "G2", "G2NF", "-BC", ];
FusionPro.Composition.repeatRecordCount = formNames.length;

var FormToUse = formNames[FusionPro.Composition.repeatRecordNumber - 1];
var outputName = Field("Agent_Code") + FormToUse + "." + FusionPro.Composition.outputFormatExtension;
FusionPro.Composition.OpenNewOutputFile(outputName);
Print("Changing to output file: " + outputName);

Link to comment
Share on other sites

I renamed the pages via Page Usage to "G2", "G2NF", "-BC"

 

I put the code you last gave me into a OnRecordStart rule.

 

When composing I get the following error: "A fatal error has occurred and FusionPro must abort. It is possible the disk is full. Composition stopped with errors. Error no 1096."

 

Job log:

 

Current working folder: /

Template File: /Form ABCDEF SMIC 0121.dif

Input File: /Excel files/0121 test.csv

Job Config File: /Form ABCDEF-Merge.cfg

Changing to output file: 912213G2.pdf

Composing record #1, input record 1, repeat 1 of 3

No page is emitted, please check page usage in your input file.

 

Changing to output file: 912213G2NF.pdf

A body page does not have master page assigned.

A blank page is emitted since no record is composed properly.

 

dlpdfdocwritepdf, progress "Doc->PageCount is zero", error: Bad parameter.

 

PDF Library Document Write Error: Bad parameter.

 

pdf_om_WriteDoc, dtl_pdf_WritePdf returned "-2"

 

Job aborted with error.

Link to comment
Share on other sites

You're sure you're using FusionPro VDP version 8.2? Referencing the page by number in SetBodyPageUsage should work there. Anyway, try this:

var formNames = [ "G2", "G2NF", "-BC", ];
FusionPro.Composition.repeatRecordCount = formNames.length;

var FormToUse = formNames[FusionPro.Composition.repeatRecordNumber - 1];

// Set all body pages to be unused initially in the Page Usage dialog.
FusionPro.Composition.SetBodyPageUsage(FormToUse, true);

var outputName = Field("Agent_Code") + FormToUse + "." + FusionPro.Composition.outputFormatExtension;
FusionPro.Composition.OpenNewOutputFile(outputName);
Print("Changing to output file: " + outputName);

Link to comment
Share on other sites

  • 2 weeks later...
  • 1 month later...

Dan,

 

I've found a new wrinkle to this merge. This merge is only for agents that don't need a photo. If they have a photo the merge is done with InDesign.

 

There is a field named "Photo". If the Photo field has a "Y" then it doesn't produce a pdf, which is what I want.

 

The problem is when there is a "Y" in the first record, FusionPro gives me the 1096 error and doesn't go any further. If there is a"Y" past record 1 it works as expected.

 

if (Field("Photo") != "Y" )

{var formNames = [ "G2", "G2NF", "-BC", ];
FusionPro.Composition.repeatRecordCount = formNames.length;

var FormToUse = formNames[FusionPro.Composition.repeatRecordNumber - 1];

// Set all body pages to be unused initially in the Page Usage dialog.
FusionPro.Composition.SetBodyPageUsage(FormToUse, true);

var outputName = Field("Agent_Code") + FormToUse + "." + FusionPro.Composition.outputFormatExtension;
FusionPro.Composition.OpenNewOutputFile(outputName);
Print("Changing to output file: " + outputName);}

Why does it stop merging if record 1 has "Y"?

 

Thanks,

Jeremy

Link to comment
Share on other sites

I've found a new wrinkle to this merge. This merge is only for agents that don't need a photo. If they have a photo the merge is done with InDesign.

 

There is a field named "Photo". If the Photo field has a "Y" then it doesn't produce a pdf, which is what I want.

 

The problem is when there is a "Y" in the first record, FusionPro gives me the 1096 error and doesn't go any further. If there is a"Y" past record 1 it works as expected.

 

...

 

Why does it stop merging if record 1 has "Y"?

I see. There are intentionally no pages in the first record. This would normally be fine, except that you're trying to then open a new output file for the next record. So FusionPro is trying to close and write the current output file that it was already working on, but there are no pages in that output file, so it can't write it, which is the error you're getting.

 

I suppose this is something that FusionPro could be a bit smarter about, but it's a combination of the page usage and chunking (multiple output files) features that's pretty uncommon.

 

Anyway, the easiest way to fix this is to add these lines after the existing code:

else
   FusionPro.Composition.composeThisRecord = false;

This tells FusionPro that, instead of a record with no pages, there's no record at all to compose. The difference seems subtle, but it's important when you're doing chunking (output to multiple files).

Link to comment
Share on other sites

  • 5 months later...

New wrinkle - I've added 2 new pages "-sig" and "-sigTS".

 

I'd like to have "G2", "G2NF", and "-BC" output to one folder and "-sig" and "-sigTS" output to a different folder. Can that be done?

 

I eliminated the code that only output records if "Photo" field had "Y" in it. Now, all records get output.

 

Thanks,

Jeremy

Link to comment
Share on other sites

New wrinkle - I've added 2 new pages "-sig" and "-sigTS".

It's getting harder for me to follow exactly what you're doing in this increasingly complex job without actually having the job files, but I think all you need to do is add those new page names to that formNames array.

I'd like to have "G2", "G2NF", and "-BC" output to one folder and "-sig" and "-sigTS" output to a different folder. Can that be done?

Yes. You can specify the folder path as well as the file name in the call to FusionPro.Composition.OpenNewOutputFile. You probably want to do something like this:

var SigFolder = "SigFolder"; // some full path here
var OtherFolder = "OtherFolder"; // some other full path here
var outputName = FormToUse.indexOf("-sig") > -1 ? SigFolder : OtherFolder;
outputName += "/" + Field("Agent_Code") + FormToUse + "." + FusionPro.Composition.outputFormatExtension;
FusionPro.Composition.OpenNewOutputFile(outputName);
Print("Changing to output file: " + outputName);

Where this will work best if you define the folders to be full (absolute) paths. I would use forward slashes here, even on Windows, so that you don't have to worry about escaping backslashes in JavaScript.

 

If you want to go a bit further, you can make it so that the output always gets made in subfolders of the output path defined in the Composition Settings dialog by doing this in OnJobStart:

outputPath = FusionPro.Composition.outputFileFullPathName.replace(/^(.*)[\\\/\:](.*)/,'$1');

Then your OnRecordStart logic can do something like this:

var SigFolder = "SigFolder"; // some relative path here
var OtherFolder = "OtherFolder"; // some other relative path here
var outputName = outputPath + "/" + (FormToUse.indexOf("-sig") > -1 ? SigFolder : OtherFolder);
outputName += "/" + Field("Agent_Code") + FormToUse + "." + FusionPro.Composition.outputFormatExtension;
FusionPro.Composition.OpenNewOutputFile(outputName);
Print("Changing to output file: " + outputName);

Where you can now hard-code just the folder names, not absolute paths.

Link to comment
Share on other sites

  • 6 months later...

Hi Dan,

 

This is working great for what I need but wanted to add one element to finalize the automation of a project I am working on. I have a two page template. Each page is outputting to separate PDF's using the rule you provided. I need the first page to output duplicate pages of the first page based on a field called "Book". So if the field "Book" has the number "4" then the first page will output to 4 pages of the first page. Have any suggestions?

 

Thanks

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