Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
1

How to insert templates into a specific place within PDF document

New Here ,
Dec 20, 2019 Dec 20, 2019

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!

TOPICS
How to , PDF forms
2.2K
Translate
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
Community Expert ,
Dec 20, 2019 Dec 20, 2019

Please read the JavaScript reference entry for the "template.spawn()" function.

 

https://help.adobe.com/en_US/acrobat/acrobat_dc_sdk/2015/HTMLHelp/#t=Acro12_MasterBook%2FJS_API_Acro...

 

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. 

 

 

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

Translate
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 ,
Dec 23, 2019 Dec 23, 2019

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

Translate
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
Community Expert ,
Dec 23, 2019 Dec 23, 2019
LATEST

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. 

 

 

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

Translate
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