RTTSoftware Support Forum
PDF-ShellTools => General => Topic started by: Nick Riviera on May 05, 2021, 10:27:06 AM
-
I have a acrobat script that I use through document javascript/pdfshell tools
The script works but the pdfs is not save, otherwise I have to open each pdf and save...
I want to run this script on multiple files and then save it automatically
Can be done this ?
acrobat javascript
var Count1 = this.numPages;
for (var p=this.numPages-1; p>=0; p--) {
for (var n=0; n<this.getPageNumWords(p); n++) {
if (getPageNthWord(p, n) == "DELETE") {
this.deletePages(p);
break;
app.execMenuItem("Save");
}
}
}
-
Try with this mixed Acrobat and PDF-ShellTools script.
var app = pdfe.CreateObject("AcroExch.App");
var baseDoc = pdfe.CreateObject("AcroExch.PDDoc");
var ProgressBar = pdfe.ProgressBar;
ProgressBar.max = pdfe.SelectedFiles.Count;
for (var i = 0; i < pdfe.SelectedFiles.Count; i++) {
try {
ProgressBar.position = i + 1;
var FileObj = pdfe.SelectedFiles(i);
var FullPathFilename = FileObj.Filename;
FileObj.Close();
pdfe.echo('Deleting keyword marked pages: ' + FullPathFilename);
baseDoc.Open(FullPathFilename);
try {
var JSObject = baseDoc.getJSObject();
var PagesGotDeleted = false;
for (var p = JSObject.numPages - 1; p >= 0; p--) {
var PageNumWords = JSObject.getPageNumWords(p);
for (var n = 0; n < PageNumWords; n++) {
if (JSObject.getPageNthWord(p, n) == "DELETE") {
JSObject.DeletePages(p);
PagesGotDeleted = true;
break;
}
}
}
if (PagesGotDeleted) {
if (baseDoc.Save(0, FullPathFilename)) {
pdfe.echo(" [OK]", 0, 1);
} else {
pdfe.echo(" [failed to save]", 0xFF0000, 1);
}
} else {
pdfe.echo(" [Keyword not found]", 0xFF, 1);
}
} catch (err) {
pdfe.echo(err, 0xFF0000);
pdfe.echo("");
}
baseDoc.Close();
} catch (err) {
pdfe.echo(err, 0xFF0000);
pdfe.echo("");
}
}
app.Exit();
pdfe.echo('\nDone');
Use the manager to import (https://www.rttsoftware.com/Manuals/STIndex.htm?pageURL=ST/English/MyScripts.htm) the attached script. You will get a "Delete pages marked by keyword [DELETE]" named script in the PDF-ShellTools context menu, My Scripts submenu.
-
Works, thanks!
Try with this mixed Acrobat and PDF-ShellTools script.
var app = pdfe.CreateObject("AcroExch.App");
var baseDoc = pdfe.CreateObject("AcroExch.PDDoc");
[/quote]