Copy link to clipboard
Copied
Hi,
I am trying to create an interactive PDF which add/deletes pages in a specific order based on a number of check boxes. Currently I can add and delete pages using a code similar to the following - which I have pieced together from a number of threads:
if(event.target.value!="Off")
{this.getTemplate("Template1" ).spawn();}
else
for (var p=this.numPages-1; p>=0; p--) {
if (this.numPages==1) break;
for (var n=0; n<this.getPageNumWords(p)-1; n++) {
if (this.getPageNthWord(p, n) == "FirstWord" && this.getPageNthWord(p, n+1) == "SecondWord" && this.getPageNthWord(p, n+2) == "ThirdWord") {
this.deletePages(p);
break;
}
}
}
However, the order in which these templates are placed into the document is important and if a check box is checked and then unchecked, the order is lost and templates are just added to the end of the document. I have attempted to specify the page that templates are inserted using: .spawn({nPage:1}) but this has led to pages being inserted on top of one another becoming illegible. Does anyone have any ideas on how to fix this?
Any help would be appreciated!
Copy link to clipboard
Copied
Please read the JavaScript reference entry for the "template.spawn()" function.
So to develop a method for inserting pages in the correct locations, you need a way to identify those locations. Using words on the page is one way, but a better method is field names.
Copy link to clipboard
Copied
Hi Thom,
I've got it thanks for replying! I do have one further query though. The script for deleting pages based off of a string of words takes a long time to process, do you have any recommendations of faster (less process heavy) methods? Would this be better based off field names too?
Thanks again
Copy link to clipboard
Copied
Yes exactly, if each page contains a uniquely idenitifiable field, then is a simple and fast operation to get the field object, and then the page the field is on.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more