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

I Need an Action Wizard to Split a specific page from multiple PDF files?

Community Beginner ,
Apr 02, 2024 Apr 02, 2024

Copy link to clipboard

Copied

I have a file with 5,000 pdfs I'd like to split a single page from each pdf and have it renamed and saved in a new folder.

TOPICS
JavaScript , PDF

Views

704

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
1 ACCEPTED SOLUTION
Community Beginner ,
Apr 02, 2024 Apr 02, 2024

Copy link to clipboard

Copied

By a Client ID# and First and Last name. 

View solution in original post

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
Community Expert ,
Apr 02, 2024 Apr 02, 2024

Copy link to clipboard

Copied

This will require a script.  How are the pages renamed?

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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
Community Beginner ,
Apr 02, 2024 Apr 02, 2024

Copy link to clipboard

Copied

By a Client ID# and First and Last name. 

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
Community Beginner ,
Apr 02, 2024 Apr 02, 2024

Copy link to clipboard

Copied

The Pdfs are already named by first and last name. We would just add the unique ID to the extracted page. 

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
Community Expert ,
Apr 02, 2024 Apr 02, 2024

Copy link to clipboard

Copied

And where does this unique ID come from?  Is it in the PDF? or will it be generated? 

If generated, how many digits? Is it random or sequential?

 

To split out the page, use the doc.extractPages() function.

https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/doc.html#extractpages

 

You have to know the page number and the file path for saving the page as a separate file. 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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
Community Beginner ,
Apr 02, 2024 Apr 02, 2024

Copy link to clipboard

Copied

I have an excel spreadsheat with the ID's and it's 1-9 numbers. 

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
Community Beginner ,
Apr 02, 2024 Apr 02, 2024

Copy link to clipboard

Copied

Also I'm not too familiar with JS.

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
Community Expert ,
Apr 02, 2024 Apr 02, 2024

Copy link to clipboard

Copied

It is possible to read a CSV file to get the associated ID file IDs, but you've just gone beyond what can be done through this forum, especially since you are not a programmer. I'd suggest you hire a developer to create this action for you. 

Or if you'd like to learn, there's lots of information and samples here for how to accomplish this process.

https://www.pdfscripting.com/public/Form-Data-Handling.cfm

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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
Community Beginner ,
Apr 02, 2024 Apr 02, 2024

Copy link to clipboard

Copied

I'll manually add the IDs to each name.

If I can just get a code  extract the documents. It would be of great help. 

I forgot to note that the pdfs contains signatures. Would that be an issue? 

 

This is what I have:

 

// Open the PDF document
var doc = app.openDoc("C:\Users\NSO\Desktop\Signatures");

// Extract pages
var extractedDoc = doc.extractPages({
nStart: 26, // Starting page number (0-based index)
nEnd: 26, // Ending page number (0-based index)
cPath: "C:\Users\NSO\Desktop\Signatures\New folder" // Path to save the extracted pages
});

// Close the original document
doc.closeDoc();

// Close the extracted document
extractedDoc.closeDoc();

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
Community Expert ,
Apr 02, 2024 Apr 02, 2024

Copy link to clipboard

Copied

The general outline of this code will work when run from the console window or an automation script.  But it has several errors and the general outline will not work in an Action. 

 

For an Action script the document object is provided in event.target. There is no need to use the "app.openDoc()" function.

 

If you read the reference entry for the "extractPages()" function you'll see that it returns NULL when the save path parameter is provided. You cannot have both the file path and get the doc object. And the paths must be complete, i.e., the path must include the file name. 

 

This is how the script should look (note this is an outline and not complete code)

 

// Build save path, assume it is a subfolder of the path to the current file
var strRoot = event.target.path.replace(/\/[^\/]+$/,"/New Folder/");
// Build save file name. For demo purposes use the current file name
var strFileName = event.target.documentFileName;  // 

// Save Extracted Page
try{
   event.target.extractPages(26,26,strRoot + strFileName);
}catch(e){app.alert("Error extracting page from:" + strFileName + "\n" + e.message);}

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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
Community Expert ,
Apr 02, 2024 Apr 02, 2024

Copy link to clipboard

Copied

LATEST

A signed (not secured) document does not prevent pages from being extracted, but the extracted pages will not be signed, even if the signature field is on one of the extracted pages. 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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