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

I have a folder with 2000 PDF files. Is there a way using Javascript to extract the first page of all PDF files in one folder and then save those individual extracted PDFs to another folder?

New Here ,
Oct 25, 2018 Oct 25, 2018

Copy link to clipboard

Copied

I have thought of two approaches to this because my folder with 2000 PDF files contains many files that only have one page.

1) Somehow find a way to determine the PDF files with more than one page, then run a script to extract and save the first page of every PDF with > one page i.e., to another folder.

2) Run a javascript in Adobe Acrobat XI to extract the first page of all 2000 PDF files in my folder and save the resulting PDFs to another folder.

I wish if possible to do this without all 2000 PDF windows opening up during the process---which will no doubt crash my computer if I try to do this will all 2000 PDF files!

So far, I have tried using the Action Wizard which carries out 3 steps:

Execute JavaScript:

  • this.extractPages(0);

Delete pages:

  • from 2 to 3

Save

  • Add to original file name a "1" after the original file name
  • Output: PDF

If I do it like this, all the files within my folder start to open. I ended the task before anything like 2000 PDFs were opened. Also, this delete option failed as it seems to be specific?

Does anybody know of a way to achieve the extraction of the first page of multiple PDF files followed by the saving of the extracted PDF files to another folder?

Kind regards,

Doug.

TOPICS
Acrobat SDK and JavaScript , Windows

Views

1.5K

Translate

Translate

Report

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 , Oct 25, 2018 Oct 25, 2018

You are on the right track, but processing 2000 files in one action may be a bit too much for Acrobat. In general, Acrobat's automation tools are not designed for continuous operation, and in my experience, you will have to limit how many files you process in one batch.

Here is how I would do this: Let's assume you have a folder called "TheFiles", and one on the same level called "FirstPages", you can use a script that extracts the first page of a document that has more than one page and write th

...

Votes

Translate

Translate
Community Expert ,
Oct 25, 2018 Oct 25, 2018

Copy link to clipboard

Copied

LATEST

You are on the right track, but processing 2000 files in one action may be a bit too much for Acrobat. In general, Acrobat's automation tools are not designed for continuous operation, and in my experience, you will have to limit how many files you process in one batch.

Here is how I would do this: Let's assume you have a folder called "TheFiles", and one on the same level called "FirstPages", you can use a script that extracts the first page of a document that has more than one page and write that first page with a new filename to the "FirstPages" output folder.

To find out if the document has more than one page, you can use the Doc.numPages property. To extract the first page, I would use the Doc.extractPages() command, but with the output filename specified (see here fore more information: Acrobat DC SDK Documentation )

if (this.numPages > 1) {

   // determine the current filename

    var idx = this.path.lastIndexOf('/');

    var baseFileName = this.path.substring(idx+1).replace(/\.[pP][dD][fF]/, "");

   var fileName =

   this.extractPages(0, 0, "../FirstPages/ " + baseFileName + "_1.pdf");

}

You can of course modify e.g. the output folder or the output filename.

The reason why Acrobat kept opening more and more files is that you did not use the version of the exportPages function that just silently writes out the exported pages and does not actually open the resulting document in the viewer.

Votes

Translate

Translate

Report

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