Skip to main content
GatsbyNZ
Known Participant
November 28, 2022
Answered

Spawning page

  • November 28, 2022
  • 2 replies
  • 5127 views

Hi,

I have a 9-page PDF with page 7 as a template, I have created a button on page 7 template page for spawning new pages, and here is the script I am using ("Task Card" is the template):

this.getTemplate("Task Card").
spawn(this.numPages-2,true,false);

I want the newly generated page to be placed right after the previously generated page, I wonder is there a better way to script it than simply "this.numPages-2"?  And ideally, no matter on which page (all the generated pages have the page spawning buttons) I click the button to generate a new page, and the page will all be added at the end of the whole list of the spawned pages. Thanks a lot.

 

Regards,

This topic has been closed for replies.
Correct answer bebarth

this.getTemplate("TemplateName").
var nPageSpawn = this.getField("PageAfterSpawn").page -1;
spawn(nPageSpawn,true,false);

Hi Thom, sorry for the last thing, I am just trying this script and the system returned an error highlighting the above, do you have any clue to it?


Hi,

I personally don't understand exactly where you want to place the spawned pages, but in your spawn line the template is missing. The script should be:

var t=this.getTemplate("TemplateName").
var nPageSpawn = this.getField("PageAfterSpawn").page -1;
t.spawn(nPageSpawn,true,false);

@+

2 replies

Thom Parker
Community Expert
Community Expert
November 28, 2022

Yes, there are few things you can do to postitively identify the spawn location.

Here are a couple techniques: 

1. Search all fields on the PDF for a specific field known to only be on the template. Collect these fields into an array, and search for the highest page number.

2. Place a field with a unqique name on the page after the location of the spawned template pages. Get the page number of this field.

  

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
GatsbyNZ
GatsbyNZAuthor
Known Participant
November 28, 2022

Hi Thom, wondering is there a particular script that can place the spawned page right before a named page (rather than a page number, because the page number will change.) Thanksm

Thom Parker
Community Expert
Community Expert
November 28, 2022

That's the point of placing a unique field on the page. It is the unique field that uniquely identifies the page. 

Say for example the field name is "PageAfterSpawn";

Then this code identifies the target page for spawning.

 

var nPageSpawn = this.getField("PageAfterSpawn").page -1;

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
bebarth
Community Expert
Community Expert
November 28, 2022

Hi,

Here is the adaptation of an example I did some times ago.

I hope that will help you.

@+

 

GatsbyNZ
GatsbyNZAuthor
Known Participant
November 28, 2022

Thanks a lot, what a great example! Appreciate it.

Regards,