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

Spawn a template to a specific location dynamically

New Here ,
Jan 30, 2020 Jan 30, 2020

I have a 22 page document with 3 hidden templates. I have three different check boxes on three different pages that when checked should show or spawn the corresponding template on the page following the check box. When unchecked it should hide/delete the tempolate. What would be the script to do this?

Best regards, Dr Phill
TOPICS
PDF forms
3.6K
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 ,
Jan 30, 2020 Jan 30, 2020

Here's the entry for the template spawn method in the Acrobat JavaScript Reference:

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

 

The first parameter indicates the page where the template page will be inserted. 

The page for the checkbox is "event.target.page", for a script in  the checkbox MouseUp event.

 

Here's some sample code for the mouseUp script

 

if(event.target.value == "Off")

     this.deletePages(event.target.page+1);

else

    this.getTemplate("Name").spawn(event.target.page, false, false);

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
Community Beginner ,
Jul 22, 2020 Jul 22, 2020

Just to follow up on this - I've managed to get this code to work in my document but am also looking to go to the page that is spawned. How would I achieve that?

 

My code is currently:

 

if(event.target.value == "Off")

this.deletePages(event.target.page+1);

else

this.getTemplate("Driving.HighwayCode").spawn(event.target.page+1, true, false);

 

Thanks.

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 ,
Jul 23, 2020 Jul 23, 2020

Example:

Go to the first page of the document.

this.pageNum = 0; 

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 ,
Jul 23, 2020 Jul 23, 2020
LATEST

The page is being spawned to "event.target.page + 1", which is the page after page where the check box is placed. So you want to set the page number to this page.

if(event.target.value == "Off")
    this.deletePages(event.target.page+1);
else
{
    this.getTemplate("Driving.HighwayCode").spawn(event.target.page+1, true, false);
    this.pageNum = event.target.page+1;
}
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