PDA

View Full Version : Print page depending on even or odd pages


mclisa81
February 10th, 2010, 07:29 AM
I have an unused body page that should either print or not print based on whether it falls on an even or odd page. The 70 pages in front of it are variable, so the count is always different. If the unused body page falls on an even page, it should print. If it is odd, it should not print. I'll attach an example. Thanks in advance.

Dan Korn
February 10th, 2010, 09:37 AM
What determines how many pages are included before the page in question? In other words, the answer to how to control whether to include your page depends on how the other pages are being added. If you're using Overflow pages, you can control how the last page is inserted in the Overflow Options dialog, by setting "Add pages" to "So Last Added Page Is Odd." If you're doing something like inserting pages from an external PDF as in this thread (http://forums.printable.com/showthread.php?t=37), you will have to key off of the page counter variable in your rule.

mclisa81
February 10th, 2010, 09:58 AM
No overflow pages used. I have 71 body pages set to unused in my template. They are turned on based on the funds the client has in their data using the following rule..

var TotalFields = 71;
var PrintVersions = new Array();
for (i = 0;i < TotalFields;i++) {
if (Field(i+1) != "") {
PrintVersions[i] = Field(i+1);
}
}
for (n = 0;n < PrintVersions.length;n++) {
var Front1 = PrintVersions[n] + "-front1";
FusionPro.Composition.SetBodyPageUsage(Front1,true );
}
}


So there could be 1-71 pages that are set to "true", and when the last page is an "odd" number of pages, I need the "BlankBack" set to "true", so it backs up the last page (if odd).

Dan Korn
February 10th, 2010, 11:42 AM
It seems to me that the value of PrintVersions.length is either going to be true or false, so you should be able to just key off of that, by doing this at the end of the rule:
FusionPro.Composition.SetBodyPageUsage("YourPageName", PrintVersions.length % 2);The modulus 2 (% 2) operator will return either 1 (true) or 0 (false) depending on whether the value of the first operand is odd or even.

mclisa81
February 11th, 2010, 06:23 AM
Your suggestion worked perfectly, as usual. Thanks Dan!:)

mclisa81
July 21st, 2011, 10:56 AM
Dan, I need to modify this rule that you helped me with last year. Instead of just needing it to be an even page count, we have turned it into a saddlestitch book so in the end, the page count needs to be divisible x4. Is there a way to modify this existing rule to incorporate this change?



var TotalFields = 67;

var PrintVersions = new Array();

// Populate array with all versions printing in current record
for (i = 0;i < TotalFields;i++) {
if (Field(i+1) != "") {
PrintVersions[i] = Field(i+1);
}
}

// Set which pages print for current record
for (n = 0;n < PrintVersions.length;n++) {
var Front1 = PrintVersions[n] + "-front1";
FusionPro.Composition.SetBodyPageUsage(Front1,true );
FusionPro.Composition.SetBodyPageUsage("BlankBack", PrintVersions.length % 2);
}
}

Thanks for all your help
Lisa

mclisa81
July 21st, 2011, 11:08 AM
I forgot to mention something. This not the whole document. I have other pages within the template. Some static, some overflow (pulling in pdfs with unknown page counts). So, I guess the question is, I have the 1 blank page that works, giving me an even number of pages. Now, can the number of pages be counted and then blanks added if needed to be divisible x4. Would seeing the template help you, help me?

Thanks again
Lisa

lisa
November 2nd, 2012, 06:34 AM
Hi Lisa,

I am trying to something very similar. I have 19 pages all set to unused in my template. The user selection in form filling will determine which pages will print and which will not.

I have two headers (graphic) for each page that I want to switch depending on if the current page is odd or even. Seems like your code should work for this.
But Im confused by this line of code

if (Field(i+1) != "") {

What is field? Is that an actual field in your DB?

Id appreciate any help you can give!
Thanks, Lisa

esmith
November 2nd, 2012, 08:00 AM
if (Field(i+1) != "") {
What is field? Is that an actual field in your DB?
mclisa was defining fields based on their column position in the data file rather than by name. "i" is defined in the FOR loop as being numbers 0-66 so "i+1" would result in "1-67". The effect is that the loop cycles through the first 67 columns of data in her data file and adds a value to an array if there is a value in that column for that record. She then uses the array to determine which pages to use for that record.

I am trying to something very similar. I have 19 pages all set to unused in my template. The user selection in form filling will determine which pages will print and which will not.

I have two headers (graphic) for each page that I want to switch depending on if the current page is odd or even. Seems like your code should work for this.
I believe mclisa's rule is applied to the OnRecordStart callback rule. Using her logic to determine whether a page should be enabled or not on your end, you could possibly assign unique names to each graphic header frame on each page and then assign the correct left- or right-hand image (via a FindGraphicFrame() function) based on whether the element in the array of active pages is even or odd. Keep in mind that the array begins with element "0" so element "1" is actually an even page.