Skip to main content
GatsbyNZ
Known Participant
Nov 28, 2022 7:40 PM UTC
Answered

Spawning page

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 is closed to new replies. Start a new post to keep the conversation going.
bebarth
bebarthCorrect answer
Community Expert
Nov 29, 2022 11:49 AM UTC

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);

@+

20 replies

Thom Parker
Community Expert
Community Expert
Nov 28, 2022 8:09 PM UTC

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.

  

 

Translate
Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
GatsbyNZ
GatsbyNZAuthor
Known Participant
Nov 28, 2022 8:19 PM UTC

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

Translate
Thom Parker
Community Expert
Community Expert
Nov 28, 2022 9:04 PM UTC

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;

 

 

Translate
Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
bebarth
Community Expert
Community Expert
Nov 28, 2022 8:02 PM UTC

Hi,

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

I hope that will help you.

@+

 

Translate
GatsbyNZ
GatsbyNZAuthor
Known Participant
Nov 28, 2022 8:16 PM UTC

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

Regards,

Translate