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

Fix a script for extract pages

Explorer ,
Dec 22, 2022 Dec 22, 2022

Copy link to clipboard

Copied

Hello everyone, a friend named Mike wrote me a certain script,
And I need someone to fix it.

 

The script takes a pdf file with 2 pages, extracts the second page in the file, (deletes it from the document) saves it in a new file with the extension cut
After that - he saves the document.

I need a fix like this:


The script takes a file with several pages, extracts the last page in the file (and deletes it from the document) and saves it in a new file with the extension cut
After that - he saves the document:

 

 

 

//Save this in the ....\Acrobat\Javascripts\ program or user directory
// as a .js file to load as Add-In

app.addSubMenu({ cName: "Custom Tools", cParent: "Edit", nPos: 0 });

app.addMenuItem({ cName: "Extract Page 2 with suffix", cParent: "Custom Tools", cExec: "extractPagesWithSuffix()"});


extractPagesWithSuffix = app.trustedFunction(function (){
var re = /.*\/|\.ai.pdf$/ig;
var filename = this.path.replace(re,"");

app.beginPriv();

this.extractPages ({ nStart: 1, nEnd: 1, cPath : "/Macintosh HD/Users/avielnatan/Desktop/" + filename + "_cut" + ".pdf"}); // Extracts page 2 to the desktop with the suffix _cut

this.deletePages({nStart: 1, nEnd: 1}); // deletes page 2 from the original file

app.execMenuItem("Save"); // saves the original file with page 1 only after page 2 is deleted from the original file
app.endPriv();
app.alert("Done Extracting Page 2 With Suffix!");
})

TOPICS
JavaScript

Views

532

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 2 Correct answers

Explorer , Dec 22, 2022 Dec 22, 2022

Mike Bro send me:

//Save this in the ....\Acrobat\Javascripts\ program or user directory
// as a .js file to load as Add-In

app.addSubMenu({ cName: "Custom Tools", cParent: "Edit", nPos: 0 });

app.addMenuItem({ cName: "Extract last Page with suffix", cParent: "Custom Tools", cExec: "extractPagesWithSuffix()"});


extractPagesWithSuffix = app.trustedFunction(function (){
var re = /.*\/|\.ai.pdf$/ig;
var filename = this.path.replace(re,"");
var lastPage = this.numPages-1;

app.beginPriv();

this.extractPages ({

...

Votes

Translate

Translate
Advisor , Dec 22, 2022 Dec 22, 2022

@aviel222,

 

I'm glad it worked for you!

 

Regards,

Mike

Votes

Translate

Translate
Community Expert ,
Dec 22, 2022 Dec 22, 2022

Copy link to clipboard

Copied

Change these two lines to:

 


this.extractPages ({ nStart: this.numPages-1, nEnd: this.numPages-1, cPath : "/Macintosh HD/Users/avielnatan/Desktop/" + filename + "_cut" + ".pdf"}); // Extracts last page to the desktop with the suffix _cut
this.deletePages({nStart: this.numPages-1, nEnd: this.numPages-1}); // deletes last page from the original file

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
Explorer ,
Dec 22, 2022 Dec 22, 2022

Copy link to clipboard

Copied

Mike Bro send me:

//Save this in the ....\Acrobat\Javascripts\ program or user directory
// as a .js file to load as Add-In

app.addSubMenu({ cName: "Custom Tools", cParent: "Edit", nPos: 0 });

app.addMenuItem({ cName: "Extract last Page with suffix", cParent: "Custom Tools", cExec: "extractPagesWithSuffix()"});


extractPagesWithSuffix = app.trustedFunction(function (){
var re = /.*\/|\.ai.pdf$/ig;
var filename = this.path.replace(re,"");
var lastPage = this.numPages-1;

app.beginPriv();

this.extractPages ({ nStart: this.numPages-1, nEnd: this.numPages-1, cPath : "/Macintosh HD/Users/avielnatan/Desktop/" + filename + "_cut" + ".pdf"}); // Extracts last page to the desktop with the suffix _cut
this.deletePages({nStart: this.numPages-1, nEnd: this.numPages-1}); // deletes last page from the original file

app.execMenuItem("Save"); // saves the original file with after last page is deleted from the original file
app.endPriv();
app.alert("Done Extracting Page 2 With Suffix!");
})

 

 

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
Advisor ,
Dec 22, 2022 Dec 22, 2022

Copy link to clipboard

Copied

@aviel222,

 

I'm glad it worked for you!

 

Regards,

Mike

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
Explorer ,
Dec 22, 2022 Dec 22, 2022

Copy link to clipboard

Copied

I have one more small request if possible.
Is it possible to do if the source file: aa.pdf
The target file will be: aaa_cut.pdf?
Double dot creates a problem for me in Windows operating system

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 22, 2022 Dec 22, 2022

Copy link to clipboard

Copied

LATEST

The regular expression has an error. 

change it to 

 

var re = /.*\/|\.ai\.pdf$/ig;

 

Now it should work

 

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