Skip to main content
Inspiring
November 9, 2023
Question

Need help spawning template

  • November 9, 2023
  • 5 replies
  • 2029 views

 

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. 

 

 

This topic has been closed for replies.

5 replies

JR Boulay
Brainiac
November 28, 2023

" 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
Inspiring
November 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)  

try67
Brainiac
November 27, 2023

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

try67
Brainiac
November 9, 2023

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

Inspiring
November 13, 2023

Can you elaborate or link me to an example?

try67
Brainiac
November 13, 2023

For example:

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

See the documentation for more details.

JR Boulay
Brainiac
November 9, 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
Bernd Alheit
Brainiac
November 9, 2023

Use true for the rename parameter.

Inspiring
November 9, 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.