Jump to content

finding the total page count in a record, and making sure page count is even


Recommended Posts

I'm working on a statement that builds out a purchase summary into a table using an external data file. There is really only one caveat, which is that the total page count for each record must be an even amount of pages.


The table starts on page three, and overflows to as many pages as it needs to. If I knew that the table would always be more than 3 pages, I'm pretty sure I could simply select the "So Last Added Page Is Even" from the Add pages dropdown within the Overflow Options dialogue box. However, not every record is long enough to warrant an overflow page.


So I attempted to write a rule that got the total page count, and added a blank page if the page count was odd:



var pageCount = FusionPro.Composition.totalPages;
if(pageCount %2 != 0)
   FusionPro.Composition.SetBodyPageUsage("ExtraPage", true);

I also tried:

var pageCount = FusionPro.Composition.countPages;


After that didn't work, I thought maybe it was because I was checking it before the record had composed, thus FP didn't yet know the total number of pages in each record. So I tried the rule in the OnRecordEnd rule. That didn't work either. Is that because that rule runs after composition, so changes to the file cannot happen? I also tried it in the OnJobEnd.


Is there a way to see what the last page number is in a record? If I could find that out, I could check against that and add the ExtraPage if it was odd.


Just for clarification, all I need to do is add a blank page if a record has an odd amount of pages.


Thanks in advance.



Link to comment
Share on other sites

In the latest version of FusionPro VDP, 9.3.36, there is a new callback rule named OnPagesInserted which was added for exactly this kind of situation. In that rule, and only in that rule, you can access the FusionPro.Composition.totalPages property, and then you can call FusionPro.Composition.SetBodyPageUsage to activate extra pages as needed.


To make sure the record outputs an even number of pages, you can add an unused Body Page to the template (with a name such as "filler"), and then do this in the OnPagesInserted rule:

FusionPro.Composition.SetBodyPageUsage("filler", FusionPro.Composition.totalPages % 2);


This can be generalized to fill signatures requiring other multiples of pages, such as a 4-page multiple. In that case, if you add unused body pages with names such as "filler1", "filler2", and "filler3", you can do this in the OnPagesInserted callback:

var fillersNeeded = (4 - (FusionPro.Composition.totalPages % 4)) % 4;
Print(FusionPro.Composition.totalPages + " pages so far, need " + fillersNeeded + " filler(s).");
for (var p = 1; p <= fillersNeeded; p++)
   FusionPro.Composition.SetBodyPageUsage("filler" + p, true);

Again, you need FusionPro 9.3.36 or later to use this feature.

Link to comment
Share on other sites

Dan, Is there a list of what has been done in release 9.3.36? The only thing i've found is where you put "UPDATE: FusionPro VDP 9.3.36 adds support for Mac OS X version 10.11 "El Capitan.". The revision history on marcom.com doesn't appear to be updated to reflect 9.3.36. thanks.PS. Thanks for all your help on these forums too!
Link to comment
Share on other sites

  • 5 months later...

This was just what I needed but I can't seem to find solution to one issue. I have a file where the last record overflows to 9 pages. Everything is fine until until it's imposed. During imposition I get an error and instead of adding 3 pages it truncates the 9th page.


Error: The number of pages in this record does not match the imposition signature: 2 pages will be truncated.


I've tried changing imposition every which way and have attached screenshot of it. It's an unusual one because of the nature of the job. How can I get around this? I'm using the coding exactly as shown here.

Link to comment
Share on other sites

I've tried changing imposition every which way and have attached screenshot of it.

Sorry, I don't see a screenshot.

It's an unusual one because of the nature of the job.

You may need to attach the job then.

How can I get around this? I'm using the coding exactly as shown here.

And what version of FusionPro?

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