Copy link to clipboard
Copied
I have been trying to get acrobat to dynamically number pages in a worksheet that spawns additional pages from templates based on user responce to questions. I have created a uniquely named text field on each page with a custom calculation script to populate each field. So far nothing I have tried has worked correctly. It will number the templates correctly but once hidden and spawned it fails.
I have attempted the below scripts:
------- Attempt 1-------
event.value= "page "+ (event.target.page + 1) +" of " + this.numPages;
calculateNow();
Result: Same page number on every page with correct total page count
------- Attempt 2-------
this.getField("Page Count1").value=this.pageNum+1 +" of "+this.numPages;
calculateNow();
Result: Required uniqe code for every text field (86) but resulted in same page count on every page with correct total pages
------- Attempt 3-------
event.value = util.printf("Page %d of %d", event.target.page+1,this.numPages);
calculateNow();
Result: Page count illogical ("-2456") with correct total pages
------- Attempt 4-------
event.value="Page "+(this.pageNum+1)+" of "+this.numPages;
calculateNow();
Result: Page count illogical ("-1,20") with correct total pages
------- Attempt 5-------
event.target.value ="Page "+(event.target.page + 1)+" of "+this.numPages;
calculateNow();
Result: Page count illogical ("-1,20") with correct total pages
Copy link to clipboard
Copied
The calculation script on a template field is run before the template is fully instantiate. At that time the page number for a hidden template is -1. To get the fields to update property, run "calculateNow()" after the spawn function, not in the calculate script. Actually its a really, really bad idea to put "calculateNow()" in a calculate script. Good way to create infinite feedback.
In fact, I would avoid using the calculate script altogether. Instead add code after the spawn to find the page number fields on each page and fill them with the proper numbers.
Copy link to clipboard
Copied
Excellent idea. I'll give this a try first thing in the morning.
Copy link to clipboard
Copied
Not too great with script but where do mean to add the code to calculate the pages?
Copy link to clipboard
Copied
It's not clear what you are asking about. Are you using templates? Templates add pages to a PDF, so the page numbers change. The poster on this thread has a script that spawns new pages with a page templates. The code for setting the new page numbers needs to be at the end of that script, i.e., after the new page(s) are spawned.