Copy link to clipboard
Copied
How do I spawn a page to appear in the middle of a pdf?
I found this Java code that spawns a page to the end of the file, while renaming all the fields.
var a = this.getTemplate("Template1"); //change your template name
a.spawn({nPage: this.numPages, bRename: true, bOverlay: false});
What do I need to change to spawn a page after page 5 the first time, and then each additional spawn will be added relative to the last page I inserted/spawned?
I am a beginner with Java.
Copy link to clipboard
Copied
if(this.numPages==10)
{a.spawn({nPage: 5, bRename: true, bOverlay: false});}
else
{a.spawn({nPage: this.pageNum+1, bRename: true, bOverlay: false});}
Change the 10 to actual number pages in your document before any spawning is done.
Copy link to clipboard
Copied
When the bOverlay paramater is set to false, the page is inserted as new page before the nPage parameter. Change this.numPages to the page number that you want the page to appear before. Example:
a.spawn({nPage: 5, bRename: true, bOverlay: false});
will spawn the page before page 6. The other spawns will have to take the new page number of the spawned page into account.
Copy link to clipboard
Copied
Thank you. That worked. How do I change the code to insert additional pages? The "before" page number is not static when I want to isnert more than one page. I am not sure I am explainign this right, so forgive my ignorance....trying to learn. Much appreciated for this Community.
Copy link to clipboard
Copied
Are you spawning the same template each time? Is the spawn button located on the template page?
Copy link to clipboard
Copied
I am spawning the same template page and I did add the button to the template page.
Copy link to clipboard
Copied
if(this.numPages==10)
{a.spawn({nPage: 5, bRename: true, bOverlay: false});}
else
{a.spawn({nPage: this.pageNum+1, bRename: true, bOverlay: false});}
Change the 10 to actual number pages in your document before any spawning is done.
Copy link to clipboard
Copied
Thank you. This worked like a charm.
Copy link to clipboard
Copied
You have to make sure you're always spawning the new pages after all the other pages you've previously spawned, or you'll get duplicate field names on them.