Copy link to clipboard
Copied
Can someone help me out with this? I have a button which places a new page in the doc, no problem. What I was wanting to do is to add a page number in the lower right hand side of the new page. As the doc grows so would the page numbers. The template places new pages after the first page so the number should be like so, 2, 3, 4, 5, 6 etc. Is there a javascript to this? If so, where can I view it and where would I place it? Thank you.
Copy link to clipboard
Copied
Hi.
Place this script as a calculation script in a text field on each page:
On static pages:
event.value = (event.target.page + 1);
On template pages:
event.value = (event.target.page[1] + 1);
Copy link to clipboard
Copied
Hi JR, I tried the lines of script you provided. They kinda work, but I was hoping to do is, to add a new page from the template. The page number should be added at that point. Is there a way to not have to add a new text field on each static pages? Then when I delete a page that I create from the template the number remains the same, it doesn't update with a new page number. Example: if I click the button to add a new page, a page number gets placed on the new page, let's say page 4, then when I add additional pages and delete page 4, all the pages keep the page numbers they were assigned. Is there a way to make the page numbers update to the new page number? Am I doing something wrong? Or not doing something right?
Copy link to clipboard
Copied
This is because calculations occurs before spawning/deleting pages.
You must add 3 lines to your script, so calculations will be made after spawning/deleting, not before.
this.calculate = false;
// here is the script that spawn/delete pages
this.calculate = true;
this.calculateNow();
Copy link to clipboard
Copied
Like so?
On static pages:
event.value = (event.target.page + 1);
this.calculate = false;
On template pages:
event.value = (event.target.page[1] + 1);
this.calculate = true;
this.calculateNow();
Did I get it right?
Copy link to clipboard
Copied
No, leave calculations events untouched.
this.calculate = false;
// here is the script that spawn/delete pages when the end user clic on the button
this.calculate = true;
this.calculateNow();
Copy link to clipboard
Copied
Hi there
I'm having the same problem as this pdf user. The code above is a bit unclear how it should be added to my existing code.
Below is my existing code. As I want my page number format to be Page x of y, I used the script below on both the static and on template page.
event.value="Page"+(event.target.page+1)+"of"+this.numPages;
The above code displays the page numbers, however there are two issues:
1. While it works on the front page numbers, it somehow displays incorrect page number on the last spawned page (i.e. Page 0 of 4).
2. If I delete a page, the page numbers do not recalculate. I added the calculate code as advised above, it didn't work for me.
Please help. Thanks.
Copy link to clipboard
Copied
Can you share your document?
Copy link to clipboard
Copied
Try this script as a calculation script in a text field on each page:
On static pages:
event.value = (event.target.page + 1) + " of " + this.numPages;
On template pages:
event.value = (event.target.page[1] + 1) + " of " + this.numPages;
Copy link to clipboard
Copied
Thanks for your reply.
Sorry I'm not able to share my document.
I already tried that code and it didn't work.
I also tried the additional calculate scripts and it didn't work. I've added them at the end of my existing script.
Copy link to clipboard
Copied
JR_Boulay wrote
Try this script as a calculation script in a text field on each page:
On static pages:
event.value = (event.target.page + 1) + " of " + this.numPages;
On template pages:
event.value = (event.target.page[1] + 1) + " of " + this.numPages;
Can you clarify static vs template pages? Where would this code go in the PDF?
Copy link to clipboard
Copied
Disregard JR_Boulay, I was able to get my code to work. Thank you so much!!
Copy link to clipboard
Copied
I mean : template page = spawned page
Copy link to clipboard
Copied
It does kind of work but per my original question there are bugs. How can I display the correct page number on the last page as this shows i.e. 0 of 4?
...and if I delete one or more pages, how can I display the correct (recalculated) page numbers, i.e. page 1 still shows page 1 of 4 even if I deleted a page? It should show page 1 of 3.
Thanks
Find more inspiration, events, and resources on the new Adobe Community
Explore Now