Skip to main content
Fiddling Orion
Inspiring
November 11, 2022
Answered

Adobe Acrobat Pro - Looking to enable a hidden page spawned to the CURRENT page using Javascript

  • November 11, 2022
  • 2 replies
  • 1594 views

Hello, I am a bit stuck as I am also new a Javascript novice. 

I have been using this script for an application to enable an applicant to add a specific set a hidden page template (ResidencePage) to the doc at a certain point.

var a = this.getTemplate("ResidencePage");
a.spawn(6, false, false);

That adds it after page 6. But, later in the doc, I want to add this function again for a different hidden page template page.

However, using this function earlier, changes the page order and screws things up for the later pages. 

Is there a way I can change the javascript formula to spawn the page to whatever the current page the user is on (as the page number may change from the earlier action)?

This topic has been closed for replies.
Correct answer Fiddling Orion

Thank you very much, as that works but spawns the page just before the current page. Sooo, I added changed your solution to this.pageNum+1 and that solves that!!! 

2 replies

try67
Community Expert
Community Expert
November 11, 2022

If you're not renaming the fields then it's actually not a problem to spawn to the current location.

Just replace 6 in your code with this.pageNum. Using event.target.page is not recommended, because that will return an array if there's more than one copy of that field.

Fiddling Orion
Fiddling OrionAuthorCorrect answer
Inspiring
November 11, 2022

Thank you very much, as that works but spawns the page just before the current page. Sooo, I added changed your solution to this.pageNum+1 and that solves that!!! 

ls_rbls
Community Expert
Community Expert
November 11, 2022

You can't just spawn a hidden template page to whatever the current page the user is on because it will basically rewrite over that page and create a bigger mess if you're not careful.

 

Maybe you meant to ask if there is a way to modify and test for subsequent spawned pages using the event.target.page method.

 

It is explained in the link below with an example:

 

 

To avoid the problem that you are struggling with, the best way to spawn a hidden template page is at the end of a document. 

 

The first item, or page, or an object in a PDF will always begin at 0 not 1, and they are created following that order in a sequence.

 

With that in mind, if you need to spawn pages correctly, it may be relevant to slightly modify and continue to test your script for the second template using a condition as shown in the link that I posted above for you.

Fiddling Orion
Inspiring
November 11, 2022

Thanks much, that's good education and some things to learn there for another project. But, got another and very simple solution in this chain now. 

ls_rbls
Community Expert
Community Expert
November 11, 2022

You're welcome