4 Replies Latest reply on Feb 2, 2017 7:48 PM by saria16163311

    delete all but the first page


      Good day all,


      I am not familiar with javascript and I hope somebody can help me with this.

      I need to run a script on a large batch of files already selected and delete all but the first page in each file, then save all to a new folder while keeping the exact same file names.

      Any help is very much appreciated.


      I should also add that I will be running this script on Adobe XI Pro and that the PDF files have different number of pages each.

        • 1. Re: delete all but the first page
          Karl Heinz Kremer Adobe Community Professional

          Usually, you would use an Action to do something like this in Adobe Acrobat Pro (Standard does not have the "Action" functionality). The problem is that you are trying to save the files to a different folder - an Action either saves the files back to the same filename (replacing the original document), or to the same folder, but with a modified filename. To save to a different folder makes things a bit more complex.


          Let's assume you have your files in a folder named Documents/MyFiles and you want to save the modified files to Documents/MyNewFiles - the important thing is that you are saving to a folder that is on the same level as your original folder.


          Something like this should work:


          var fileName = this.documentFileName;
          try {
            this.deletePages(1, this.numPages - 1);
          } catch (e) {
          this.saveAs("../MyNewFiles/" + fileName);


          For this to work, you will have to add one "Execute Javascript" (under "More Tools") to your Action, and then use this script (after making any modifications to adjust it to your specific environment).

          • 2. Re: delete all but the first page
            Joel_Geraci Adobe Community Professional

            An easier solution would be to simply duplicate the folder in question, rename it, then run the action against the new folder.

            • 3. Re: delete all but the first page
              Karl Heinz Kremer Adobe Community Professional

              That is true, but it could potentially cause a dramatic data loss: I never create actions that modify the original file, I always modify the filename. This prevents me from accidentally wiping out a directory because I either selected the wrong directory, or the wrong action to run. We all make mistakes, and I just don't trust myself that much

              • 4. Re: delete all but the first page
                saria16163311 Level 1

                Thank you Karl, your code worked perfectly.

                I did not the use the built in delete action because my files dfo not have the same number of pages. Wheteher I save to the same folder, or a different one, unless the number of pages are the same, it will not work.

                Thank you again, the code did work for me.