Skip to main content
Participating Frequently
February 1, 2023
Answered

Spawn templates after a specific page with checkboxes

  • February 1, 2023
  • 3 replies
  • 3695 views

I have 3 checkboxes named (NYC, NY and NJ) that spawn a template (all 3 are different templates) when checked and hides it when unchecked, but I need it to show a specific page not at the end, what am I missing? (im not a coder)

 

if(event.target.value!="Off")
{this.getTemplate("NYC" ).hidden=false;}
else
{this.getTemplate("NYC" ).hidden=true;}

This topic has been closed for replies.
Correct answer Thom Parker

The code I provided needs to be put into the original code that uses the check state to determine whether the template is spawned or deleted. 

if(event.target.value!="Off")
{this.getTemplate("NYC" ).spawn(nTargetPageNumber, false, false);}
else
{this.deletePages(nTargetPageNumber);}

 

The trick for removing the page is to determine the actual page number. This is simple if nothing has changed since the template was spawned, but if other templates were spawned, then you'll need some way to find the page. The best technique is to have a field with a unique name on the page. 

 

 

3 replies

Participant
October 6, 2023

Thank You Thom - I think it will give me something to work with 

Keith

Thom Parker
Community Expert
Community Expert
February 1, 2023

The code you've shown does not "spawn" the page template. It hides and shows the actual template, which will always be placed at the end of the document. This will not work in the free Reader. To make the page appear at the desired location it has to be "spawned". 

 

this.getTemplate("NYC" ).spawn(nTargetPageNumber, false, false);

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Ryan MCAuthor
Participating Frequently
February 1, 2023

Thank for you this very helpful. Now if I uncheck the box it "spawns" again is that supposed to be?

Thom Parker
Community Expert
Thom ParkerCommunity ExpertCorrect answer
Community Expert
February 1, 2023

The code I provided needs to be put into the original code that uses the check state to determine whether the template is spawned or deleted. 

if(event.target.value!="Off")
{this.getTemplate("NYC" ).spawn(nTargetPageNumber, false, false);}
else
{this.deletePages(nTargetPageNumber);}

 

The trick for removing the page is to determine the actual page number. This is simple if nothing has changed since the template was spawned, but if other templates were spawned, then you'll need some way to find the page. The best technique is to have a field with a unique name on the page. 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Bernd Alheit
Community Expert
Community Expert
February 1, 2023

You can spawn template pages where you want.

Ryan MCAuthor
Participating Frequently
February 1, 2023

I can move it yes manually, but when i click on the checkbox it re spawns at the end of the form