Skip to main content
Known Participant
May 27, 2022
Answered

Acrobat spawning pages at a specified point in the document

  • May 27, 2022
  • 1 reply
  • 553 views

I have a contents page with checkboxes that I need to set to spawn template pages from. I need them to spawn at specified points in the document, so they come after pages already in the PDF. I can't use page numbers as the page count will vary depedning on what's been selected.

 

So I was thinking of making them spawn based on a page name or title, so it spawns after that page? Is that possible at all?

 

Thanks for ay help

This topic has been closed for replies.
Correct answer try67

So if the field is named "Marker1", for example, you can use this code:

this.getTemplate("Template1").spawn(this.getField("Marker1").page, true, false);

 

However, this will not work correctly if the Template page has fields that you want to rename and also to spawn it more than once, as the field names in the spawned pages will be duplicates of each other. You will need to find the last spawned page from that group, and then spawn the new page after it for it to work properly.

1 reply

try67
Community Expert
Community Expert
May 27, 2022

Depends what you mean by "page name"... If you're referring to static text on the page, that will be quite tricky to implement (although not impossible). A much easier solution is to place (hidden) fields on those pages and then access that field in your code and get its current page number. Then spawn the new page after that number.

Known Participant
May 27, 2022

Sorry yeah a hidden field acting as page title could work. Do you know the code I'd need to make that work? So it spawns the template after the page with the hidden field

 

Thanks alot for your help 

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
May 27, 2022

So if the field is named "Marker1", for example, you can use this code:

this.getTemplate("Template1").spawn(this.getField("Marker1").page, true, false);

 

However, this will not work correctly if the Template page has fields that you want to rename and also to spawn it more than once, as the field names in the spawned pages will be duplicates of each other. You will need to find the last spawned page from that group, and then spawn the new page after it for it to work properly.