Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


Print function with multiple conditions if

New Here ,
Aug 29, 2021 Aug 29, 2021

Copy link to clipboard

Copied

hi
I'm trying to create a function that, based on certain variables, allows me to print some pages of a pdf file with certain parameters to other pages with certain parameters.
I have 4 fields named "SURNAME" distinguished from each other by the number "_2, _3, _4".
var t1 = this.getField ("SURNAME"). value;
var t2 = this.getField ("SURNAME_2"). value;
var t3 = this.getField ("SURNAME_3"). value;
var t4 = this.getField ("SURNAME_4"). value;
If the "SURNAME_4" field is not empty I want these pages to be printed.
[[2,29]]; pp.DuplexType = 2; pp.NumCopies = 1; this.print (pp);
[[30,35]]; pp.DuplexType = 2; pp.NumCopies = 4; this.print (pp);
[[36,51]]; pp.DuplexType = 1; pp.NumCopies = 1; this.print (pp);
[[52,59]]; pp.DuplexType = 2; pp.NumCopies = 1; this.print (pp);
[[60,63]]; pp.DuplexType = 2; pp.NumCopies = 1; this.print (pp);
[[64,80]]; pp.DuplexType = 1; pp.NumCopies = 1; this.print (pp);
[[81,96]]; pp.DuplexType = 2; pp.NumCopies = 1; this.print (pp);
Otherwise, if the field is empty, I want pages 2 to 19 to be printed. If SURNAME_3 is not empty, I want pages 2 to 19 to be printed. If it is not empty, I want the pages from 2 to 17. And so on until you reach the "SURNAME" field with the printing of pages 2 to 15.
Then I have a second condition. I have 4 fields named "PROFESSION"
var s2 = this.getField ("PROFESSION-2"). value;
var s3 = this.getField ("PROFESSION-3"). value;
var s4 = this.getField ("PROFESSION-4"). value;
If the "PROFESSION-4" field is equal to "NO", I want the pages [[30,35]] to be printed in reverse font and 3 copies
This is the feature I have created so far, but I realize it is too long

var pp = this.getPrintParams();
var s2= this.getField("PROFESSION-2").value;
var s3= this.getField("PROFESSION-3").value;
var s4= this.getField("PROFESSION-4").value;
var t1= this.getField("SURNAME").value;
var t2= this.getField("SURNAME_2").value;
var t3= this.getField("SURNAME_3").value;
var t4= this.getField("SURNAME_4").value;
if (t4!=""&&t3!=""&&t2!=""&&t1!=""){pp.printRange = [[2,29]];pp.DuplexType =2;pp.NumCopies=1;this.print(pp); }
if (t4!=""&&t3!=""&&t2!=""&&t1!=""){pp.printRange = [[30,35]];pp.DuplexType =2;pp.NumCopies=4;this.print(pp); }
if (t4!=""&&t3!=""&&t2!=""&&t1!=""&&s4==”NO”){pp.printRange = [[30,35]];pp.DuplexType =2;pp.NumCopies=3;this.print(pp); }
if (t4!=""&&t3!=""&&t2!=""&&t1!=""&&s4==”NO”&&s3==”NO”){pp.printRange = [[30,35]];pp.DuplexType =2;pp.NumCopies=2;this.print(pp); }
if (t4!=""&&t3!=""&&t2!=""&&t1!=""&&s4==”NO”&&s3==”NO”&&s2==”NO”){pp.printRange = [[30,35]];pp.DuplexType =2;pp.NumCopies=1;this.print(pp); }

else if(t4==""&&t3!=""&&t2!=""&&t1!=""){pp.firstPage = this.pageNum +1,pp.lastPage = this.pageNum +18,pp.DuplexType = 2,pp.NumCopies = 1;}
else if(t4==""&&t3==""&&t2!=""&&t1!=""){pp.firstPage = this.pageNum +1,pp.lastPage = this.pageNum +16,pp.DuplexType = 2,pp.NumCopies = 1;}
else if(t4==""&&t3==""&&t2==""&&t1!=""){pp.firstPage = this.pageNum +1,pp.lastPage = this.pageNum +14,pp.DuplexType = 2,pp.NumCopies = 1;}
pp.colorOverride = pp.constants.colorOverrides.blackandwhite;
pp.pageHandling = pp.constants.handling.fit;
pp.printerName = getField("PRINTER").value;
pp.interactive = pp.constants.interactionLevel.silent;

TOPICS
How to, JavaScript, Print and prepress

Views

48

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Aug 29, 2021 Aug 29, 2021

Copy link to clipboard

Copied

You can use something like this:

 

if (t4!="") {
	// Print some pages when SURNAME_4 is not empty
} else {
	// Print some other pages, if SURNAME_4 is empty
}

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 29, 2021 Aug 29, 2021

Copy link to clipboard

Copied

Hi. Thanks for the tip. I am interested in understanding if there is a formula that gives me the ability to print multiple pages with the relative parameters while maintaining the same condition "if".
For instance
if (t4!=""&&t3!=""&&t2!=""&&t1!=""){pp.printRange = [[2,29]];pp.DuplexType =2;pp.NumCopies=1;this.print(pp);pp.printRange[[36,51]]; pp.DuplexType = 1; pp.NumCopies = 1; this.print (pp); pp.printRange[[52,59]]; pp.DuplexType = 2; pp.NumCopies = 1; this.print (pp)} etc
This function does not work because it sends the command to print the last page selection, i.e. from page 52 to page 59. The question I ask at the forum is whether there is a way to build a similar formula correctly.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Aug 29, 2021 Aug 29, 2021

Copy link to clipboard

Copied

Your code is modifying the same print params object for multiple prints. I have not analyzed how the print params object works, but you're description of the behavior of your code would suggest that changing it after calling the print function modifies what the print function does, i.e., the print behavior is intimately connected to the specific print params object. 

 

I'd suggest getting a new print params object for consecutive print operations.    

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Aug 29, 2021 Aug 29, 2021

Copy link to clipboard

Copied

Only the first command should work because you've forgotten to add "=" after printRange in the last two instances... If you fix that I don't see why it shouldn't work just fine.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 31, 2021 Aug 31, 2021

Copy link to clipboard

Copied

LATEST

Thank you very much for your help.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines