2 Replies Latest reply on Dec 17, 2010 9:32 AM by steveald366

    Extract Multi Page PDF to Multiple files


      I have been tasked with separating out groups of pages from several multi page PDF files. I believe that it is possible through Javascript. I have tried to do my own research and have found some code, but it isn't quite doing what I need it to do and I don't know how to get it to that point.


      The basics are:
      I have multiple PDFs that are roughly 800 pages each.
      I need to find a way to split the large 800 page PDF into PDFs of 12 pages each. So, pages 1-12, 13-24, 25-36 etc.
      The file names are not important as long as they are different. 001, 002, 003 is fine, or Filename001, etc.
      I am not picky about the save location. In the same location as the original PDF is great, or whatever is easiest.
      I can definitely handle splitting the large files manually by executing code in the javascript window if that is the easiest method. If I need to create a batch process I believe I can set that up as well.

      I am working on Acrobat 8 pro.


      The code I have now is:


      for(var i=0,j=0; i<this.numPages; i+=12,j++)
         var oNewDoc = this.extractPages({nStart: i, nEnd: i + 12});
         var cFlName = "File" + ".pdf";
         var cPath = oNewDoc.path.replace(oNewDoc.documentFileName,cFlName);


      Right now it doesn't seem to do much of anything. It creates .tmp files, but they appear to close without saving. I'm afraid I just don't know enough about javascript yet to get past it. Any help or guidance would be greatly appreciated.



        • 1. Re: Extract Multi Page PDF to Multiple files

          This may help you, but it needs one more piece to the puzzle for my needs.


          I found the following code for creating a Batch Sequence using JavaScript to extract pages from a multi-page pdf file.


          It works fine, but it creates a separate file for each single page, naming them Extract001.pdf, Extract002.pdf, etc.


          I need to know how to modify it so it will save 3 pages at a time (1st file is pages 1-3 of the original pdf, 2nd file is pages 4-6, etc.).



          var filename = "Extract";


          var nihe=1;


          try {

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



                             nStart: i,

                             cPath: filename+ util.printf("%03d",i+nihe) +".pdf"


          } catch (e) { console.println("Aborted: " + e) }



          Can someone help?


          Thank you.

          • 2. Re: Extract Multi Page PDF to Multiple files
            steveald366 Level 1



            In case you still need it, the folks over at acrobatusers.com helped me fix the code I showed above to work as needed. Here it is with what I believe are the correct modifications to work for your situation. The new files are saved in the same directory as the original file. Sorry, I can't explain how it works - just that it does.



            var filename = "Filename";


            var nihe=1;


            try {
            for ( var i = 0; i < this.numPages; i+=12)
            nStart: i, nEnd: i + 11,
            cPath: filename+ util.printf("%03d",i/12+1) +".pdf"
            } catch (e) { console.println("Aborted: " + e) }