Skip to main content
Known Participant
January 30, 2020
Question

Spawn a template to a specific location dynamically

  • January 30, 2020
  • 1 reply
  • 3556 views

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?

This topic has been closed for replies.

1 reply

Thom Parker
Community Expert
Community Expert
January 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_AcroJS%2FTemplate_methods.htm%23TOC_spawnbc-1&rhtocid=_6_1_8_74_1_0

 

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 PDFScriptingUse the Acrobat JavaScript Reference early and often
Participant
July 23, 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.

Bernd Alheit
Community Expert
Community Expert
July 23, 2020

Example:

Go to the first page of the document.

this.pageNum = 0;