Skip to main content
jfb45671162
Participating Frequently
March 10, 2016
Answered

Dynamic Page Numbering script isn't working on spawned pages?

  • March 10, 2016
  • 1 reply
  • 6544 views

I'm working in Acrobat Pro XI on a 4 page document with a button that allows a template pages to be inserted after page 3.  I created a button for this and it is working fine.  But each page has a text field that is supposed to auto update all of the page numbers.  The code looks like this:

event.value="Page "+(event.target.page+1)+" of "+this.numPages;

calculateNow();

On the four pages visible when the file is opened it is working perfectly; they will update from "Page 1 of 4" to "1 of 5", etc. without any problems.  However, the inserted template pages are very random.  Sometimes the first spawned one will work and say Page 4 of 5 but sometimes it will say Page 0 of 4.  It's worth mentioning that even when it says Page 4 of 5 printing that page shows it saying Page 0 of 4 again.  And any additional pages spawned after that will list a bunch of random numbers out of the correct number of pages.  So it will look like "Page 7, 6, 5, 4, 31 of 9".

I've been looking through a lot of previously asked questions and haven't seen any quite like this. 

This topic has been closed for replies.
Correct answer George_Johnson

If you want to add a new page for each press of the button, you can simplify the code to:

getTemplate("Addittional Collaborators").spawn(numPages, true, false);

but you'll have to add code to correctly set the "page x of y" field values. Post again if you have trouble with that part.

1 reply

Inspiring
March 10, 2016

Where did you place that script exactly? Can you show the code you're using to spawn the template that includes the field that's used to display the "Page 1 of 4" text?

jfb45671162
Participating Frequently
March 10, 2016

I placed the script in the custom calculation portion of a text field.  And I have the spawn template button separate from the "Page x of y" text.  The trigger is Mouse Up and the code is:

var a = this.getTemplate("Addittional Collaborators");

for (var i = 3; i<4; i++)

a.spawn(i, true, false);

May 30, 2016

Thank you so much.  I felt like I was hitting my head on the wall trying to figure it out.


Hi all

I have a further issue where my text is not updating.  I have a spawned page button on page 2 of a 3 page doc that inserts a copy of p2 between p2 and p3. The code I use is successful in doing this

"var pagecount = 0;

var pagepos = 0;

pagecount = this.numpages;

pagepos = pagecount-1;

gettemplate("newtemplate").spawn({npage:pagepos, brename: true, boverlay:false});"

Howver the footer does not change the numbering.  I also tried adding a text box with the following code in the custom calculation but get nada

this.value="page"+this.pagenum +" of "+this.numpages;

calculatenow();

Any ideas?

Thanks in advance