8 Replies Latest reply on Mar 22, 2009 5:30 PM by dhishok

    Extract PDF pages with it's actual page numbers...

    dhishok Level 1
      Hi scripting gurus,

      We have more than 40 of PDF documents each document contain multiple pages. Using Acrobat Professional 7.0 and 8.0 with MAC platform. We have the script to extract the pages and to suffix running numbers with the document name, please find the script below. For example CH01.pdf document total number of pages is 10, but the actual page number starts with 11. So We have to extract each pages as individual documents and the page number will followed by document name with "_" separation, (Eg: CH01_11.pdf). I have tried so many ways to include the page numbers with the document name but i can't.

      /*Split pdf pages with pNum suffixed*/
      var rename = /.*\/|\.pdf$/ig;
      var startName = this.path.replace(rename,"");

      for (var i = 1, j = 0; j < numPages; i += 1, j += 1) {
      extractPages ({
      nStart : j,
      nEnd : j == numPages - 1 ? j : j + 0,
      cPath : "/Macintosh HD/Users/Beaconpmg/Desktop/ExtractFolder/"+startName+"_"+i+".pdf"
      });
      }

      So please can anyone look into this and help for me.
      Thanks in advance.

      Regards
      Thiyagu
        • 1. Re: Extract PDF pages with it's actual page numbers...
          gkaiseril MVP & Adobe Community Professional
          In Acrobat JavaScript, the page numbering starts at "0" and not "1".

          If you know the actual difference in pages, you only need to run the JavaScript page numbers and add the offset.

          Create a global variable for the total page offset

          // see if we need to define a global offset first file
          if(global.fPageOffset == undefined) {
          var global.fPageOffset = 10; // start at 10

          /*Split pdf pages with pNum suffixed*/
          var rename = /.*\/|\.pdf$/ig;
          var startName = this.path.replace(rename,"");

          for (var i = 0; i < numPages; i++) {
          this.extractPages ({ nStart : i, nEnd : i == numPages - 1 , cPath : "/Macintosh HD/Users/Beaconpmg/Desktop/ExtractFolder/" + startName + "_" + (i + global.PageOffset) + ".pdf" });
          }

          // add finished file's number of pages to global page offest
          global.fPageOffest += this.numPages;
          • 2. Re: Extract PDF pages with it's actual page numbers...
            dhishok Level 1
            Hi Geo Kaiser,

            Thanks for your kind support. I have copied this script in acrobat's JavaScript editor, by creating new batch process but the script editor not accepting the "global.PageOffset" syntax, it shows some error in it. I have tried it in both acrobat 7.0 and 8.0 but i am unable to find the solution. Can you please check it and help for me.

            Regards
            Thiyagu
            • 3. Re: Extract PDF pages with it's actual page numbers...
              Larry G. Schneider Adobe Community Professional & MVP
              Did you correct the spelling error in the last lines?
              • 4. Re: Extract PDF pages with it's actual page numbers...
                dhishok Level 1
                Hi Larry,

                Thanks to looking into this. Even though if i correct the spelling mistake it shows some error in "if" condition. i.e. showing error in fourth line of the script. Its because "if" condition is not get completed. I have tried but nothing happened. Can you please look into this and help for me. And please suggest that how can i put actual pages numbers in the file name of each document after extracting the pages from multi page PDF document. It is the main requirement for me. Thanks in advance.

                Regards
                Thiyagu
                • 5. Re: Extract PDF pages with it's actual page numbers...
                  try67 MVP & Adobe Community Professional
                  First of all, replace numPages with this.numPages
                  Also, this doesn't make any sense:
                  nEnd : i == numPages - 1

                  You're using a comparison to specify the last page to be extracted? A comparison returns a boolean.
                  • 6. Re: Extract PDF pages with it's actual page numbers...
                    dhishok Level 1
                    Hi,

                    I have tried but it is not working. Its showing the same error (missing ; before statement)in 4th line of the script. Can you check this. Thanks in advance for your support.

                    Regards
                    Thiyagu
                    • 7. Re: Extract PDF pages with it's actual page numbers...
                      try67 MVP & Adobe Community Professional
                      I don't know what you changed. You need to post the code.
                      • 8. Re: Extract PDF pages with it's actual page numbers...
                        dhishok Level 1
                        try67

                        First of all, replace numPages with this.numPages
                        Also, this doesn't make any sense:
                        nEnd : i == numPages - 1

                        I have tried what you have said above, but it is not working. Its showing the same error (missing ; before statement)in 4th line of the script.

                        Please find the complete code below;

                        // see if we need to define a global offset first file
                        if(global.fPageOffset == undefined) {
                        var global.fPageOffset = 10; // start at 10

                        /*Split pdf pages with pNum suffixed*/
                        var rename = /.*\/|\.pdf$/ig;
                        var startName = this.path.replace(rename,"");

                        for (var i = 0; i < this.numPages; i++) { this.extractPages ({ nStart : i, nEnd : i == this.numPages - 1 , cPath : "/Macintosh HD/Users/Beaconpmg/Desktop/ExtractFolder/" + startName + "_" + (i + global.PageOffset) + ".pdf" }); }

                        // add finished file's number of pages to global page offest
                        global.fPageOffest += this.numPages;

                        Regards
                        Thiyagu