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

Need help spawning template

Explorer ,
Nov 09, 2023 Nov 09, 2023

 

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

Use true for the rename parameter.

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

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. 

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

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


Acrobate du PDF, InDesigner et Photoshopographe
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 ,
Nov 09, 2023 Nov 09, 2023

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

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

Can you elaborate or link me to an example?

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

For example:

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

See the documentation for more details.

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

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

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

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

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

 


Acrobate du PDF, InDesigner et Photoshopographe
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