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

Spawn templates after a specific page with checkboxes

Community Beginner ,
Feb 01, 2023 Feb 01, 2023

Copy link to clipboard

Copied

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;}

TOPICS
Create PDFs , General troubleshooting , How to , JavaScript , PDF forms

Views

1.5K

Translate

Translate

Report

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

correct answers 1 Correct answer

Community Expert , Feb 01, 2023 Feb 01, 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 t

...

Votes

Translate

Translate
Community Expert ,
Feb 01, 2023 Feb 01, 2023

Copy link to clipboard

Copied

You can spawn template pages where you want.

Votes

Translate

Translate

Report

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 ,
Feb 01, 2023 Feb 01, 2023

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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 ,
Feb 01, 2023 Feb 01, 2023

Copy link to clipboard

Copied

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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

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 ,
Feb 01, 2023 Feb 01, 2023

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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 ,
Feb 01, 2023 Feb 01, 2023

Copy link to clipboard

Copied

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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

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 ,
Feb 01, 2023 Feb 01, 2023

Copy link to clipboard

Copied

Thank you very much Thom, it worked perfectly.

Votes

Translate

Translate

Report

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 ,
Oct 03, 2023 Oct 03, 2023

Copy link to clipboard

Copied

quote

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. 

 

 


By @Thom Parker

Hi Thom would you have an example or link to your Dot.Com (Subscribed) as an example 

Votes

Translate

Translate

Report

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 ,
Oct 04, 2023 Oct 04, 2023

Copy link to clipboard

Copied

No I don't. But there are a few considerations.

 

1. If the fields are renamed, then the code needs to loop over all fields to find the unique one on the page.

 

2. If the template is spanwned more than once, then you'll need to have a way of determining the one you want. For example, if it's the last one, then you'll need to collect all the page numbers for the uique field and then select the last.  This process is slightly different if the fields on the spawned page are not renamed.  In that case the field.page property will contain an array of page numbers. 

 

3. If the template page is hidden, which it should be, then code will find a field with an associated page number of -1.  The code needs to specifically ignore this case. 

 

So here's an example that fits with this thread. It assumes the template is spawned only once and the fields are not renamed.

 

var oFld  = this.getField("UniqeName");

// if the page property of the field is a single number, then no spawning has taken place
if(typeof(oFld.page) == "object")
{// page property is an array, so must be spawned
    var nPage = oFld.page[1];
    this.deletePages(nPage);
} 

 

 

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

Votes

Translate

Translate

Report

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 ,
Oct 06, 2023 Oct 06, 2023

Copy link to clipboard

Copied

LATEST

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

Keith

Votes

Translate

Translate

Report

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