Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

delete all but the first page

New Here ,
Jan 30, 2017 Jan 30, 2017

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.

TOPICS
Acrobat SDK and JavaScript
2.9K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jan 30, 2017 Jan 30, 2017

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

...
Translate
Community Expert ,
Jan 30, 2017 Jan 30, 2017

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

  console.println(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).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 30, 2017 Jan 30, 2017

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 30, 2017 Jan 30, 2017

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 02, 2017 Feb 02, 2017
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines