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!");
})
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!");
})
Copy link to clipboard
Copied
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
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!");
})
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
The regular expression has an error.
change it to
var re = /.*\/|\.ai\.pdf$/ig;
Now it should work
Use the Acrobat JavaScript Reference early and often

