Looking to run a script in Acrobat DC Pro
Hello. Thank you for taking the time to read this. As the title says, I am attempting to run a script in Acrobat which technically runs as it says complete but the process takes about a second to run. For context, I am attempting to set the document properties, OCR, and search for predefined terms, and highlight when those terms are found within the document. Here is what the code looks like. Any information that you may be able to provide would be appreciated.
// Clear Document Properties
this.info.Author = "";
this.info.Title = "";
this.info.Subject = "";
this.info.Keywords = "";
this.info.Creator = "";
this.info.Producer = "";
this.info.PageLayout = "Default";
this.info.Zoom = "Default";
// Set Initial View to Bookmarks Panel and Page
this.viewerPreferences = {
pageMode: "bookmarks",
nonFullScreenPageMode: "bookmarks"
};
// OCR the Document
var nNumPages = this.numPages;
for (var i = 0; i < nNumPages; i++) {
var oPage = this.getPageNth(i);
oPage.getText({ nStart: 0, nEnd: -1 });
}
// Highlight the Search Terms
var colHilite = color.yellow;
var aSearchTerms = ["Addendum", "Appendices", "Appendix", "Attachment", "Below", "Cited", "Describe", "Deviation", "Figure", "File", "Footnote", "Graph", "Lab", "Method", "Notebook", "Protocol", "Provide", "Reference", "Report", "Section", "See", "Shown", "Study", "Table"];
for (var i = 0; i < nNumPages; i++) {
var oPage = this.getPageNth(i);
for (var j = 0; j < aSearchTerms.length; j++) {
var sSearchTerm = aSearchTerms[j];
var aMatches = oPage.getAnnots({ type: "Text", subtype: "Highlight", quadPoints: [[], [], [], []], search: { query: sSearchTerm, matchCase: false, wholeWord: true } });
if (aMatches != null) {
for (var k = 0; k < aMatches.length; k++) {
var oMatch = aMatches[k];
oMatch.type = "Highlight";
oMatch.strokeColor = colHilite;
}
}
}
}
// Save the Document with the Same Name
var sFilePath = this.path;
var sFileName = this.documentFileName;
var oSaveAs = new File(sFilePath + "/" + sFileName);
this.saveAs(oSaveAs);
