Copy link to clipboard
Copied
I have a two page document that I would like the end user to be able to click a button and two new pages spawn.
I was able to figure out how to get one page to spawn but I can't seem to get both from the same button click.
This is the java script I am using:
var a = this.getTemplate ("Account Placement New"); a.spawn();
The new templates is Guarantor Placement New.
Copy link to clipboard
Copied
Use this code and replace xxx with template 1 name and yyy with template 2 name :
this.spawnPageFromTemplate("xxx",this.numPages, false, false);
this.spawnPageFromTemplate("yyy",this.numPages, false, false);
Copy link to clipboard
Copied
Use this code and replace xxx with template 1 name and yyy with template 2 name :
this.spawnPageFromTemplate("xxx",this.numPages, false, false);
this.spawnPageFromTemplate("yyy",this.numPages, false, false);
Copy link to clipboard
Copied
Thank you that worked perfectly!
Copy link to clipboard
Copied
You should not be using this method. It's deprecated and could stop working at any moment when a new update is released. Use the spawn method of the Template object, instead.
Copy link to clipboard
Copied
I agree with Try67, use the "template.spawn" method. Do not use the older and deprecated "doc.spawnPageFromTemplate"
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
I am incredily new to this so thank you both for the input. I'm not entirely familar with how to use the "template.spawn" method as opposed to the "doc.spawnPageFromTemplate" that Nesa provided.
Would this new method look like :
template.spawn("xxx",this.numPages, false, false);
template.spawn("yyy",this.numPages, false, false);
This is a previous formatting I was using but it would only pull one template at a time :
var a = this.getTemplate ("Account Placement New"); a.spawn();
Copy link to clipboard
Copied
Try this:
getTemplate("xxx").spawn(this.numPages, false, false);
getTemplate("yyy").spawn(this.numPages, false, false);
Copy link to clipboard
Copied
I had this same question, I was wondering if I have to add +1 for the second template (in bold below):
getTemplate("xxx").spawn(this.numPages, false, false);
getTemplate("yyy").spawn(this.numPages +1, false, false);
Copy link to clipboard
Copied
The first spawn will increase the number of pages by one, so adding one to the number of pages is unecessary. But it also shouldn't matter because the last page is the last page. Try it and see what happens.
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
This works, great, if I want my spawned pages to appear at the end of my form, however, I need the pages to be added after the page with my checkbox (page 2) that creates the spawning.
What is the code to ensure all 6 pf my spawned pages appear after page 2?
I have one that works really well, but am having trouble getting it to work for the spawning of multiple pages:
var a = this.getTemplate ("Risks");
a.spawn({nPage: this.pageNum+1, bRename: true, bOverlay: false});
this.getField("P" + (this.pageNum+1 - 1) + "Risks").setFocus();
Copy link to clipboard
Copied
That's not a good idea if you want to spawn the page more than once, as you'll get duplicate field names.
If you do want to do it just change nPage: this.pageNum+1 to nPage: 1.
Copy link to clipboard
Copied
I am utalizing this java script to generate new page templates :
var a = this.getTemplate ("Guarantor Placement New"); a.spawn();var a = this.getTemplate ("Account Placement New"); a.spawn();
The original page has a calculated field where we are using sum (+) to calculate certain fields. The problem that creates is each time a new template is spawned it will change the name of the fields to have P3.Account Placement New. (field name from origianl page) . Is there a custom calculated script with a wildcard that will pick up those fields?
Copy link to clipboard
Copied
The calculation script has to build the field names on the fly, by adding the spawned template prefix to the base field name.
The spawed prefix can be extracted from the name of the calculated field, like this:
var cPrefix = (event.target.page != -1)?event.targetName.split(".").slice(0,2).join(".")+".":"";
Add this code to the top of your calculation script.
Use the Acrobat JavaScript Reference early and often

