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

Need help spawning template

Explorer ,
Nov 09, 2023 Nov 09, 2023

Copy link to clipboard

Copied

 

Have Acrobat Pro.  Brand new to Javascript and Page Templates though.  Helping someone who wants a button that can create an additional "page2" from the form.  Below is the code I am using that I found elsewhere. 

 

this.spawnPageFromTemplate ({
cTemplate: this.getNthTemplate(0),
bRename: false,
});
this.pageNum = this.numPages-1;
this.zoom=100;

 

Problems:  It creates a clone of Page2, including any text that has already been entered. Don't really want that. And if I start typing on either page, it just duplicates it across both pages (typin HELLO on page 2 also makes it appear on page 3).  Can't have that. 

 

 

TOPICS
JavaScript , Modern Acrobat , PDF forms

Views

953

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 ,
Nov 09, 2023 Nov 09, 2023

Copy link to clipboard

Copied

Use true for the rename parameter.

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
Explorer ,
Nov 09, 2023 Nov 09, 2023

Copy link to clipboard

Copied

Thank you!    Looks like I have to do something about the page numbering in the corner as well. I will do some poking around here to see what I can find on that.

 

Also, is there a way to enforce a maximum amount of pages in a file?  To prevent someone from clicking this 30 times. Not a big deal, but I was asked. 

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 ,
Nov 09, 2023 Nov 09, 2023

Copy link to clipboard

Copied

" is there a way to enforce a maximum amount of pages in a file? "

You should add a condition:

 

if (this.numPage == 1) {
this.spawnPageFromTemplate ({cTemplate: this.getNthTemplate(0), bRename: false});
this.pageNum = this.numPages-1;
this.zoom=100;
}

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 ,
Nov 09, 2023 Nov 09, 2023

Copy link to clipboard

Copied

You should not use the spawnPageFromTemplate method. It was replaced by the spawn method of the Template object.

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
Explorer ,
Nov 13, 2023 Nov 13, 2023

Copy link to clipboard

Copied

Can you elaborate or link me to 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 ,
Nov 13, 2023 Nov 13, 2023

Copy link to clipboard

Copied

For example:

this.templates[0].spawn({nPage: 0, bRename: false, bOverlay: false});

See the documentation for more details.

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
Explorer ,
Nov 27, 2023 Nov 27, 2023

Copy link to clipboard

Copied

Update.  Is it possible to have page numbering that automagically changes when new pages are added?   (via the previous javas script or another method)  

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 ,
Nov 27, 2023 Nov 27, 2023

Copy link to clipboard

Copied

Yes, if you add it using fields, which can be updated dynamically.

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 ,
Nov 28, 2023 Nov 28, 2023

Copy link to clipboard

Copied

LATEST

" Is it possible to have page numbering that automagically changes when new pages are added?"

Yes.

 

Use this calculation script in a text field for static pages (where the page number is a number):

event.value = (event.target.page + 1);

 

Use this calculation script in a text field for templates, and spawned, pages (where the spawned page number is the last number in an array):

var aNumPag = event.target.page;
event.value = ((aNumPag[aNumPag.length-1]) + 1);

 

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