8 Replies Latest reply on Jul 17, 2008 9:41 AM by (Dirk_Hollstein)

    Adding page numbering through a script.

    Level 1
      Hello forum members,

      I am having a hard time to add page numbers on actual pdf pages.

      Here is what I have:
      - Adobe Acrobat Prof. 7.0 and Win XP.
      - ca. 200 PDF files with pages that should be continuously numbered without putting them into one big pdf-file. Instead, the pdf files should stay individual files even after numbering.

      Here is what I can do:
      I wrote a javascript (in the batch section) that numbers all the thumbnails in the files. It works fine. But I cannot find the right command to add the page numbers on the individual pdf-"pages". Can you pls. point me in the direction I have to look for? Do I have to add a watermark at the position I want the numbering to appear or do I miss something obvious? Thanks in advance.

      Greetings,
      dirk
        • 1. Re: Adding page numbering through a script.
          gkaiseril MVP & Adobe Community Professional
          You could add a footer to each page of a uniquely named field to each page.
          • 2. Re: Adding page numbering through a script.
            Level 1
            Thank you. However, after trying several things I did not yet come up with a solution.

            I tried the following code, which did not work - at all!

            for ( var i = 0; i < this.pageNum; i++ )
            {

            var name = "myButton" + i;
            var type = "text";
            var page = i;
            var location = [100, 472, 172, 400];
            var myField = this.addField( name, type, page, location );

            /* actually, I get no field object, but a null object back. Do not know what is going wrong so, no debug information for me on this one*/

            }

            This is basically the example from the Acrobat JavaScript manual (p.90) - and it does not work for me: there is nothing on the page to be seen, still no error in the debugger. What am I doing wrong? And what do I have to do, so that a unique field appears on each page?

            Again, thanks in advance for the answer.

            Greetings,
            dirk
            • 3. Re: Adding page numbering through a script.
              Bernd Alheit Adobe Community Professional & MVP
              When you execute View > Navigation Panels > Fields can you see the fields?
              • 4. Re: Adding page numbering through a script.
                Level 1
                Hello Bernd Alheit,

                thanks, with your hint I've found that the Fields are there, still they are invisible. I will try further.

                In the meantime any comments and code snippets are very welcome. ;-)

                E.g. is TextField the form you would go for?
                How exactly do I put this into a footer, just by putting it in the right position on the page?

                Greetings,
                dirk
                • 5. Re: Adding page numbering through a script.
                  Bernd Alheit Adobe Community Professional & MVP
                  > with your hint I've found that the Fields are there, still they are invisible.

                  You may also put page numbers in the fields.

                  > How exactly do I put this into a footer, just by putting it in the right position on the page?

                  Yes.
                  • 6. Re: Adding page numbering through a script.
                    George_Johnson MVP & Adobe Community Professional
                    That code should create a field that is one inch by one inch. If you can't see it, maybe you just need to add a visible border, background, or enter some text. If that doesn't work, is the page rotated? Is the field set to Hidden? If you use the text field tool to examine the field properties (without making any changes), does that make any difference?

                    George
                    • 7. Re: Adding page numbering through a script.
                      gkaiseril MVP & Adobe Community Professional
                      // to prevent reallocating
                      // define some constant variables
                      var name;
                      var page;
                      var myField;
                      // defne constant variables with constant values
                      var type = "text";
                      var location = [100, 472, 172, 400];

                      for ( var i = 0; i < this.numPages; i++ ) {

                      name = "myButton." + i;
                      page = i;
                      myField = this.addField( name, type, page, location );

                      /* actually, I get no field object, but a null object back. Do not know what is going wrong so, no debug information for me on this one*/

                      // additional code to fillin field with menaningful data
                      myField.delay = true; // delay updating in JavaScript
                      myField.alignment = "center";
                      myField.borderStyle = border.s;
                      myField.textSize = 0; // auto sized
                      myField.fillColor = color.transparent;
                      myField.strokeColor = color.transparent;
                      myField.textColor = color.black;
                      myField.textFont = font.Times
                      myField.value = myField.defaultValue = i + 1; // page number adjustment
                      myField.delay = false; // restore updating
                      }
                      • 8. Re: Adding page numbering through a script.
                        Level 1
                        Hello forum members,
                        thank you very much for your replies, thanks to your help it works now!

                        I just had to change one more property:

                        myField.readonly = true;

                        which makes the field not user selectable. (Just for other people, who may look for a solution to the same problem.)

                        Many regards and have a nice day!
                        dirk

                        I post the complete solution here:

                        /* Script to number your pages */

                        this.setPageLabels(0, ["D", "Page-", global.my_count]);

                        var name;
                        var page;
                        var myField;
                        var type = "text";
                        var location = [272, 40, 310, 20];

                        for ( var i = 0; i < this.numPages; i++ ) {

                        name = "Page " + i;
                        page = i;
                        myField = this.addField( name, type, page, location );

                        myField.delay = true; // delay updating in JavaScript
                        myField.alignment = "center";
                        myField.borderStyle = border.s;
                        myField.textSize = 8; // auto sized
                        myField.fillColor = color.transparent;
                        myField.strokeColor = color.transparent;
                        myField.textColor = color.black;
                        myField.textFont = font.Times;
                        myField.value = global.my_count + i; // page number adjustment
                        myField.readonly = true;
                        myField.delay = false; // restore updating

                        }

                        global.my_count = global.my_count + numPages;