Go Back   MarcomCentral (PTI) and FusionPro User Communities > Software-Related Talk > FusionPro® VDP Creator

Notices

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old December 3rd, 2015, 01:58 PM
CCS_Printing CCS_Printing is offline
Junior Community Member
 
Join Date: Feb 2011
Posts: 34
Default Adding pages to make output PDF divisible by 4

What I need is a bit more complex than the title suggests. There are two separate sections in this book where the client can choose 1 to 5 optional pages. Each new section needs to start on the left, so if an uneven number of pages is chosen a filler page specific to that section will need placed. After that has happened the entire book (which will always be an even number of pages at this point) will need two specific pages placed at then end if it's not divisible by four for saddle stitch.

I've poured over the forums and other samples I have, but just can't quite get it working. Here are some helpful posts I referenced:

Inserting Multi-page PDF variable graphics

Print page depending on even or odd pages

I want to make an array for each of the two sections, count those pages and activate an unused body page if the count is odd. I'm using this in an OnRecordStart rule. Here's the code I've been trying to massage, taken and modified from a sample file:

Code:
var counter = 0;
    
    PAGEArray = [Field("FundCare_Orange1"), Field("Dental_Orange2"), Field("FlexSpend_Orange3"), Field("PlansWork_Orange4"), Field("HowToHSA_Orange5"), Field("ClientUpload_Orange")]
        


        var PAGECount = 0;
        for (i = 0 ; i < PAGEArray.length ; i++)
        {
            if (PAGEArray[i] != "")
            {
            counter++;
            var Pic = new FusionProResource(PAGEArray[i], "graphic", "true");
            var PicPages = Pic.countPages;
     
            if (PicPages % 2 > 0)
                    {
                         FusionPro.Composition.SetBodyPageUsage(“Orange_Filler1”, "true");
                    }            
            }
        }
But that just activates the unused body page anytime the array is true (not empty), and I can't seem to get the countPages aspect to work. When I use Print("PAGECount is " + PAGECount) and view the log, I simply get PAGECount is 0 repeated for each of the fields in the array that's populated.

As far as counting the pages of each complete record and activating the two unused body pages at the end based on whether or not it's divisible by four, I was thinking along the same lines but am not sure how to include the pages from the base template in the count, the pages that aren't part of a graphic field.

Any help is really appreciated, I always try to research and resolve things on my own as it really helps me learn, but I need some tutelage here and I'm running out of time. Thanks in advance!

OSX 10.10.5
Acrobat 10.1.16
FusionPro 9.3.15

Last edited by CCS_Printing; December 3rd, 2015 at 02:01 PM.. Reason: Add software info
Reply With Quote
  #2  
Old December 3rd, 2015, 07:34 PM
step's Avatar
step step is offline
Senior Contributor
 
Join Date: Jan 2010
Location: Charlotte, NC
Posts: 955
Default Re: Adding pages to make output PDF divisible by 4

Quote:
Originally Posted by CCS_Printing View Post
What I need is a bit more complex than the title suggests. There are two separate sections in this book where the client can choose 1 to 5 optional pages. Each new section needs to start on the left, so if an uneven number of pages is chosen a filler page specific to that section will need placed.
After that has happened the entire book (which will always be an even number of pages at this point) will need two specific pages placed at then end if it's not divisible by four for saddle stitch.
Okay. How many pages is the book if the client does not select any additional pages in your two sections? I'm going to assume that it's a number divisible by 4.

Quote:
Originally Posted by CCS_Printing View Post
I want to make an array for each of the two sections, count those pages and activate an unused body page if the count is odd. I'm using this in an OnRecordStart rule. Here's the code I've been trying to massage, taken and modified from a sample file:

Code:
var counter = 0;
    
    PAGEArray = [Field("FundCare_Orange1"), Field("Dental_Orange2"), Field("FlexSpend_Orange3"), Field("PlansWork_Orange4"), Field("HowToHSA_Orange5"), Field("ClientUpload_Orange")]
        


        var PAGECount = 0;
        for (i = 0 ; i < PAGEArray.length ; i++)
        {
            if (PAGEArray[i] != "")
            {
            counter++;
            var Pic = new FusionProResource(PAGEArray[i], "graphic", "true");
            var PicPages = Pic.countPages;
     
            if (PicPages % 2 > 0)
                    {
                         FusionPro.Composition.SetBodyPageUsage(“Orange_Filler1”, "true");
                    }            
            }
        }
But that just activates the unused body page anytime the array is true (not empty), and I can't seem to get the countPages aspect to work.
That's a good start. I'm going to assume that each of those fields in the PAGEArray represent 1 of 5 potential pages. If that's the case, then that would explain why your "Orange_Filler1" page is being turned on when the page count is odd (or 1 in this case). Moreover, if each PDF resource referenced in those fields is 1 page, then there's really no point in counting the pages or even converting it to a FusionPro Resource for that matter. Instead you could filter the array and determine the page count by the length of the array like this:
Code:
var docs = [Field("FundCare_Orange1"),Field("Dental_Orange2"),Field("FlexSpend_Orange3"),Field("PlansWork_Orange4"),Field("HowToHSA_Orange5"),Field("ClientUpload_Orange")].filter(String);
FusionPro.Composition.SetBodyPageUsage("Orange_Filler1", docs.length % 2);
Quote:
Originally Posted by CCS_Printing View Post
When I use Print("PAGECount is " + PAGECount) and view the log, I simply get PAGECount is 0 repeated for each of the fields in the array that's populated.
Well that's because you defined PAGECount as 0 and never incremented it. In order to make your Print statement work, you'd have to make the following revisions:
Code:
PAGEArray = [Field("FundCare_Orange1"), Field("Dental_Orange2"), Field("FlexSpend_Orange3"), Field("PlansWork_Orange4"), Field("HowToHSA_Orange5"), Field("ClientUpload_Orange")]

var PAGECount = 0;
for (i = 0 ; i < PAGEArray.length ; i++)
{
    if (PAGEArray[i] != "")
    {
    var Pic = new FusionProResource(PAGEArray[i], "graphic", "true");
    var PicPages = Pic.countPages;
    PAGECount += PicPages;
    if (PicPages % 2 > 0)
            {
                 FusionPro.Composition.SetBodyPageUsage("Orange_Filler1", true);
            }            
    }
}

Print("PAGECount is " + PAGECount)
Quote:
Originally Posted by CCS_Printing View Post
As far as counting the pages of each complete record and activating the two unused body pages at the end based on whether or not it's divisible by four, I was thinking along the same lines but am not sure how to include the pages from the base template in the count, the pages that aren't part of a graphic field.
Are you saying you don't know how many pages are in your template? Maybe you could try this:
Code:
var endPages = [
    // These are the names of the pages that will be
    // turned on to make the totalPage count == 4
    'FillerPage1',
    'FillerPage2',
    'FillerPage3'
];
var pagesNeeded = 4-(FusionPro.Composition.totalPages%4 || 4);
for (var i = 0; i < pagesNeeded; i++)
    FusionPro.Composition.SetBodyPageUsage(endPages[i], true);
And if you feel like collecting your template or posting a sample, that would probably clear up a lot of the things I just guessed on. Good luck!
__________________
Ste Pennell
FusionPro VDP Creator 9.3.15
Adobe Acrobat X 10.1.1
Mac OS X 10.12

LinkedIn
Reply With Quote
  #3  
Old December 7th, 2015, 06:40 PM
CCS_Printing CCS_Printing is offline
Junior Community Member
 
Join Date: Feb 2011
Posts: 34
Default Re: Adding pages to make output PDF divisible by 4

This is fantastic Step, thank you! There are actually 14 pages that will always be there, so if they don't add any optional sections or upload a section the two end filler pages will be added. Unfortunately I can't upload the file as is due to the nature of the material. But here's more detail:

14 static pages and 3 sections (Green, Orange, and Blue) with optional pages.
Green = 1 optional section with 2 pages.

Orange = 5 optional sections that are 1 page each and 1 option for uploading a PDF of varying page count.

Blue = 4 optional sections that are 1 page each

The Green section is simple, and this does exactly what I need for the Blue section (great idea to simply count the length of the array):

Quote:
Instead you could filter the array and determine the page count by the length of the array like this:
Code:
var docs = [Field("FundCare_Orange1"),Field("Dental_Orange2"),Field("FlexSpend_Orange3"),Field("PlansWork_Orange4"),Field("HowToHSA_Orange5"),Field("ClientUpload_Orange")].filter(String); 
FusionPro.Composition.SetBodyPageUsage("Orange_Filler1", docs.length % 2);
The page count is now appearing in the log after I incremented the PAGECount variable, thanks! It's still all or nothing; if the array has no value the filler page won't be added, but if it has any value at all it will be added. I tried using the same logic from the Blue section by applying the modulus 2 to the Pic resource created from the array, but I'm obviously still applying something incorrectly:

Code:
PAGEArray = [Field("FundCare_Orange1"), Field("Dental_Orange2"), Field("FlexSpend_Orange3"), Field("PlansWork_Orange4"), Field("HowToHSA_Orange5"), Field("ClientUpload_Orange")]

var PAGECount = 0;
for (i = 0 ; i < PAGEArray.length ; i++)
{
    if (PAGEArray[i] != "")
    {
    var Pic = new FusionProResource(PAGEArray[i], "graphic", "true");
    var PicPages = Pic.countPages;
    PAGECount += PicPages;
    if (PicPages % 2 > 0)
            {
                 FusionPro.Composition.SetBodyPageUsage("Orange_Filler1", Pic.totalPages % 2);
            }            
    }
}

Print("PAGECount is " + PAGECount)
Once the Orange section is working properly it will always be an even page count at this point. So this logically looks like it should work too, but I wasn't getting any result after filling in the names of my specific unused body pages. I still have this placed in the OnRecordStart rule:

Quote:
Are you saying you don't know how many pages are in your template? Maybe you could try this:
Code:
var endPages = [     
// These are the names of the pages that will be     
// turned on to make the totalPage count == 4     
'End Filler Left',     
'End Filler Right'     
]; 
var pagesNeeded = 4-(FusionPro.Composition.totalPages%4 || 4); 
for (var i = 0; i < pagesNeeded; i++)
FusionPro.Composition.SetBodyPageUsage(endPages[i], true);
I feel like this is all really close, and, the help is very much appreciated. I'll try to pay it forward when I'm able!
__________________
OSX 10.11.6
Acrobat DC
FusionPro 10.0.16
Reply With Quote
  #4  
Old December 8th, 2015, 10:45 AM
step's Avatar
step step is offline
Senior Contributor
 
Join Date: Jan 2010
Location: Charlotte, NC
Posts: 955
Default Re: Adding pages to make output PDF divisible by 4

Quote:
Originally Posted by CCS_Printing View Post
14 static pages and 3 sections (Green, Orange, and Blue) with optional pages.
Green = 1 optional section with 2 pages.
Orange = 5 optional sections that are 1 page each and 1 option for uploading a PDF of varying page count.
Blue = 4 optional sections that are 1 page each
Okay cool. Good to know. How are you adding the "sections?" I'm assuming you have 3 separate text rules set up to handle each section and each of those 3 pages is allowed to overflow if needed with the section-specific filler page following the overflow page in case it's needed. Is that correct? If you wanted to simplify things and do it all within the onRecordStart rule, with only one text frame and one overflow page you'd be able to if you brought in your "filler" pages as resources instead of making them part of your template – just something to think about. I will come back to this topic momentarily.

Quote:
Originally Posted by CCS_Printing View Post
The page count is now appearing in the log after I incremented the PAGECount variable, thanks! It's still all or nothing; if the array has no value the filler page won't be added, but if it has any value at all it will be added. I tried using the same logic from the Blue section by applying the modulus 2 to the Pic resource created from the array, but I'm obviously still applying something incorrectly:
Code:
PAGEArray = [Field("FundCare_Orange1"), Field("Dental_Orange2"), Field("FlexSpend_Orange3"), Field("PlansWork_Orange4"), Field("HowToHSA_Orange5"), Field("ClientUpload_Orange")]

var PAGECount = 0;
for (i = 0 ; i < PAGEArray.length ; i++)
{
    if (PAGEArray[i] != "")
    {
    var Pic = new FusionProResource(PAGEArray[i], "graphic", "true");
    var PicPages = Pic.countPages;
    PAGECount += PicPages;
    if (PicPages % 2 > 0)
            {
                 FusionPro.Composition.SetBodyPageUsage("Orange_Filler1", Pic.totalPages % 2);
            }            
    }
}

Print("PAGECount is " + PAGECount)
'totalPages' is not a property of FusionPro resources so 'Pic.totalPages' won't work – you'd have to write 'Pic.countPages.' Aside from that, you're stepping through each field in that array and turning on/off the filler page based on whether the number of pages in each resource is odd/even. What you need to do is pull the part where you're toggling the filler page out of that for loop and only do it once based on the total page count (PAGECount):
Code:
PAGEArray = [Field("FundCare_Orange1"), Field("Dental_Orange2"), Field("FlexSpend_Orange3"), Field("PlansWork_Orange4"), Field("HowToHSA_Orange5"), Field("ClientUpload_Orange")]

var PAGECount = 0;
for (i = 0 ; i < PAGEArray.length ; i++)
{
    if (PAGEArray[i] != "")
    {
	    var Pic = new FusionProResource(PAGEArray[i], "graphic", "true");
	    var PicPages = Pic.countPages;
	    PAGECount += PicPages;
    }
}

if (PicPages % 2 > 0)
{
    FusionPro.Composition.SetBodyPageUsage("Orange_Filler1", true);
}            

Print("PAGECount is " + PAGECount)
After your clarifications and if my aforementioned assumptions are correct, I think what you want to do is this:
Code:
var pages = 14; // Number of static pages
var endPages = ['End Filler Left','End Filler Right']; // Names of the Filler Pages at the end

// Sections (Named in accordance to their "filler" page)
sections = {
    'Orange_Filler1': [
        Field("FundCare_Orange1"), 
        Field("Dental_Orange2"), 
        Field("FlexSpend_Orange3"), 
        Field("PlansWork_Orange4"), 
        Field("HowToHSA_Orange5"), 
        Field("ClientUpload_Orange")
    ], 
    'Green_Filler1': [
        Field("Green1")
    ],
    'Blue_Filler1': [
        Field("Blue1"),
        Field("Blue2"),
        Field("Blue3"),
        Field("Blue4")
    ]
};

for (i in sections) {
    pgCount = 0;
    sections[i].filter(String).forEach(function(s){ 
        pgCount += CreateResource(s, 'graphic').countPages;
    });
    pages += pgCount;
    if (pgCount % 2)
        FusionPro.Composition.SetBodyPageUsage(i, pages++);
}

var pagesNeeded = 4-(pages%4 || 4);

while (pagesNeeded--)
    FusionPro.Composition.SetBodyPageUsage(endPages[pagesNeeded], true);
Here's what it's doing:
The 'sections' object has 3 properties: 'Orange_Filler1', 'Green_Filler1' and 'Blue_Filler1'. These are the names of your "filler" pages. I do realize that you probably don't have a "green" filler page because it'll be even either way (2 pages or 0 pages) but the other names need to match what you've named your body pages so make adjustments as needed. The value of each property is an array of the fields that hold the name of the resource used to comprise each section.

The 'for' loop steps through the 'sections' object and:
  • Filters each array (removing empty fields)
  • Creates a resource from the remaining fields in order to get a page count
  • Updates the total number of pages (pages)
  • And depending on whether or not the section is odd/even, the filler sheet is activated and the page count is incremented to account for the filler sheet

Finally, a while loop is used to turn on extra pages to make the total page count divisible by 4.

As I mentioned before, you can also use this code to assign the sections to a single frame that is set to overflow (assuming that you create resources for your "filler" pages named by the 'sections' property to which they correspond ('Orange_Filler1.pdf'):
Code:
var frameName = 'TextFrame'; // Name of Text Frame to display sections
var result = []; // Array to hold sections
var pages = 14; // Number of static pages
var endPages = ['End Filler Left','End Filler Right']; // Names of the Filler Pages at the end

// Sections (Named in accordance to their "filler" page)
sections = {
    'Orange_Filler1.pdf': [
        Field("FundCare_Orange1"), 
        Field("Dental_Orange2"), 
        Field("FlexSpend_Orange3"), 
        Field("PlansWork_Orange4"), 
        Field("HowToHSA_Orange5"), 
        Field("ClientUpload_Orange")
    ], 
    'Green_Filler1.pdf': [
        Field("Green1")
    ],
    'Blue_Filler1.pdf': [
        Field("Blue1"),
        Field("Blue2"),
        Field("Blue3"),
        Field("Blue4")
    ]
};

function addPage(res) {
    res = CreateResource(res, 'graphic');
    for (var n=1; n<=res.countPages; n++) {
        res.pagenumber = n;
        result.push(res.content)
        pgCount++
    }
}

for (i in sections) {
    pgCount = 0;
    sections[i].filter(String).forEach(function(s){ addPage(s); });
    if (pgCount % 2) addPage(i);
    pages += pgCount;
}

FindTextFrame(frameName).content = result.join('<p>');

var pagesNeeded = 4-(pages%4 || 4);

while (pagesNeeded--)
    FusionPro.Composition.SetBodyPageUsage(endPages[pagesNeeded], true);
__________________
Ste Pennell
FusionPro VDP Creator 9.3.15
Adobe Acrobat X 10.1.1
Mac OS X 10.12

LinkedIn

Last edited by step; December 8th, 2015 at 04:03 PM.. Reason: Typo
Reply With Quote
  #5  
Old December 14th, 2015, 02:12 PM
CCS_Printing CCS_Printing is offline
Junior Community Member
 
Join Date: Feb 2011
Posts: 34
Default Re: Adding pages to make output PDF divisible by 4

Thanks, sorry for the delay. This does exactly what I was trying to do:

Code:
var pages = 14; // Number of static pages
var endPages = ['End Filler Left','End Filler Right']; // Names of the Filler Pages at the end

// Sections (Named in accordance to their "filler" page)
sections = {
    'Orange_Filler1': [
        Field("FundCare_Orange1"), 
        Field("Dental_Orange2"), 
        Field("FlexSpend_Orange3"), 
        Field("PlansWork_Orange4"), 
        Field("HowToHSA_Orange5"), 
        Field("ClientUpload_Orange")
    ], 
    'Green_Filler1': [
        Field("ConsultPhysician_Green")
    ],
    'Blue_Filler1': [
        Field("EmpAssist_Blue1"),
        Field("SupportMoms_Blue2"),
        Field("NICU_Blue3"),
        Field("MatProg_Blue4")
    ]
};

for (i in sections) {
    pgCount = 0;
    sections[i].filter(String).forEach(function(s){ 
        pgCount += CreateResource(s, 'graphic').countPages;
    });
    pages += pgCount;
    if (pgCount % 2)
        FusionPro.Composition.SetBodyPageUsage(i, pages++);
}

var pagesNeeded = 4-(pages%4 || 4);

while (pagesNeeded--)
    FusionPro.Composition.SetBodyPageUsage(endPages[pagesNeeded%2], true);
Making all sections elements of one array and using .forEach simplified it. Thanks again Step, this was extremely helpful!
__________________
OSX 10.11.6
Acrobat DC
FusionPro 10.0.16
Reply With Quote
Reply

Tags
array, pagecount, saddlestitch

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 08:01 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) 2011, PTI Marketing Technologies™, Inc.