13 Replies Latest reply on Feb 16, 2017 2:41 PM by MM2016

    Template page number

    pdfUser1 Level 1

      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.

        • 1. Re: Template page number
          JR_Boulay Adobe Community Professional

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

          • 2. Re: Template page number
            pdfUser1 Level 1

            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?

            • 3. Re: Template page number
              JR_Boulay Adobe Community Professional

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

              • 4. Re: Template page number
                pdfUser1 Level 1

                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?

                • 5. Re: Template page number
                  JR_Boulay Adobe Community Professional

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

                  • 6. Re: Template page number
                    MM2016

                     

                    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.

                    • 7. Re: Template page number
                      JR_Boulay Adobe Community Professional

                      Can you share your document?

                      • 8. Re: Template page number
                        JR_Boulay Adobe Community Professional

                        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;

                        • 9. Re: Template page number
                          MM2016 Level 1

                          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.

                          • 10. Re: Template page number
                            kehumphr Level 1

                            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?

                            • 11. Re: Template page number
                              kehumphr Level 1

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

                              • 12. Re: Template page number
                                JR_Boulay Adobe Community Professional

                                I mean : template page = spawned page

                                • 13. Re: Template page number
                                  MM2016 Level 1

                                  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