Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Template page number

Participant ,
Dec 15, 2016 Dec 15, 2016

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.

TOPICS
Acrobat SDK and JavaScript , Windows
1.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 18, 2016 Dec 18, 2016

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);


Acrobate du PDF, InDesigner et Photoshopographe
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Dec 18, 2016 Dec 18, 2016

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 19, 2016 Dec 19, 2016

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();


Acrobate du PDF, InDesigner et Photoshopographe
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Dec 20, 2016 Dec 20, 2016

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 20, 2016 Dec 20, 2016

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();


Acrobate du PDF, InDesigner et Photoshopographe
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 15, 2017 Feb 15, 2017

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 16, 2017 Feb 16, 2017

Can you share your document?


Acrobate du PDF, InDesigner et Photoshopographe
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 16, 2017 Feb 16, 2017

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;


Acrobate du PDF, InDesigner et Photoshopographe
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 16, 2017 Feb 16, 2017

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 16, 2017 Feb 16, 2017

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 16, 2017 Feb 16, 2017

Disregard JR_Boulay, I was able to get my code to work. Thank you so much!!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 16, 2017 Feb 16, 2017

I mean : template page = spawned page


Acrobate du PDF, InDesigner et Photoshopographe
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 16, 2017 Feb 16, 2017
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines