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.
Copy link to clipboard
Copied
Use true for the rename parameter.
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.
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;
}
Copy link to clipboard
Copied
You should not use the spawnPageFromTemplate method. It was replaced by the spawn method of the Template object.
Copy link to clipboard
Copied
Can you elaborate or link me to an example?
Copy link to clipboard
Copied
For example:
this.templates[0].spawn({nPage: 0, bRename: false, bOverlay: false});
See the documentation for more details.
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)
Copy link to clipboard
Copied
Yes, if you add it using fields, which can be updated dynamically.
Copy link to clipboard
Copied
" 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);