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

JS to Extract Multiple Pages and Name as Page Label

New Here ,
Mar 10, 2016 Mar 10, 2016

Copy link to clipboard

Copied

Good Morning! We have a group of employees that often taken a PDF that contains multiple pages (in the range of 200-500 pages) and extract them out into separate PDF's to load into a system. Often times, these large PDF's that they begin with hold page labels for each and every page, but when extracting, they lose these page labels and the individual files are named differently. What we're aiming to do is have a javascript that they can run to extract all pages out of a multi-paged PDF and in that process, it name the individual PDF files the same name as their page label.

I believe the two functions that we're dealing with are Doc.getPageLabel() and Doc.extractPages() but we're unsure as to how to tie this into a javascript that will do what we need it to do. Unfortunately, none of us have any experience with JS. I appreciate any and every ones help! Thank you!

TOPICS
Acrobat SDK and JavaScript , Windows

Views

2.8K

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 ,
Mar 10, 2016 Mar 10, 2016

Copy link to clipboard

Copied

From what context do you want to use this script? From a menu item? An Action? The JS Console?

Basically you have it right. The only thing missing is a loop that iterates over all the pages, extracting each one using its label.

The basic code would be something like this:

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

    this.extractPages(p, p, this.path.replace(this.documentFileName, this.getPageLabel(p) + ".pdf"));

}

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
New Here ,
Mar 10, 2016 Mar 10, 2016

Copy link to clipboard

Copied

What ever would best suit this objective. I was assuming that it would need to be an 'Add-On Tool' but if there is a better way of approaching it, we are definitely open to advice. Thank you!

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 ,
Mar 10, 2016 Mar 10, 2016

Copy link to clipboard

Copied

That's possible, but it would require a more complex script. If you have Acrobat Pro you can just create a new Action, put that code into it and then run it on your files directly. That's probably the easiest way of using it.

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
New Here ,
Jul 18, 2018 Jul 18, 2018

Copy link to clipboard

Copied

This totally worked for me, exact same situation. Thanks a ton!

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
New Here ,
Dec 14, 2023 Dec 14, 2023

Copy link to clipboard

Copied

how do you run it, where do you run it?

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 ,
Dec 14, 2023 Dec 14, 2023

Copy link to clipboard

Copied

From the JS Console: Press Ctrl+J, paste the code into the console, select it with the mouse and press Ctrl+Enter to run it.

 

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
New Here ,
Mar 15, 2024 Mar 15, 2024

Copy link to clipboard

Copied

Arda33440142dp57_0-1710512459659.png

 

what is wrong with me?

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 ,
Mar 15, 2024 Mar 15, 2024

Copy link to clipboard

Copied

You must select (with the mouse or keyboard) the full code before executing it.

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
New Here ,
Mar 15, 2024 Mar 15, 2024

Copy link to clipboard

Copied

Arda33440142dp57_0-1710512808863.png

 


Thank You! worked! is it possible make it without number ?

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 ,
Mar 15, 2024 Mar 15, 2024

Copy link to clipboard

Copied

This is a part of the page label, most likely. Try replacing this part of the code:

this.getPageLabel(p)

With:

this.getPageLabel(p).replace(/^\[\d+\]\s/, "")

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
New Here ,
Mar 18, 2024 Mar 18, 2024

Copy link to clipboard

Copied

LATEST

Thank you! it is worked.

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