Page counting [Javascript]
Copy link to clipboard
Copied
Hello, I'm trying to make a dynamic page counter that will display the total number of pages on my pdf document (I have templates spawn and I delete pages aswell). the current code i am using is:
this.getField("PageNo").value = this.numPages;
This is located in document Javascript.
The problem that I am having is that the field nearly never shows the right number and dose not update when the page numbers change.
Is there a fix for this?
Thank you for your help in advance!
Copy link to clipboard
Copied
Is there a more reliable way to do this?
Copy link to clipboard
Copied
Use this also where you spawn and delete pages.
Copy link to clipboard
Copied
That code set the field pageNo at the moment it is run. Nothing will change it automatically later. What you haven't told us is what event(s) you use to call that code?
Copy link to clipboard
Copied
The problem is that adding or deleting pages will not cause the calculation event to trigger, so it will not show the correct number after you do that. You will have to manually trigger all calculations in your script, by adding this command to it:
this.calculateNow();
Copy link to clipboard
Copied
PS. If this is indeed a calculation script then change it to:
event.value = this.numPages;
If it's not, then just add that line directly to your spawn/delete script, instead of the call to calculateNow.

