Copy link to clipboard
Copied
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);
Copy link to clipboard
Copied
Hi @nickl14077405 ,
Have you checked in the Developer's Console (CRT+J keyboard combination to open it) if the script is throwing any errors?
How long is this PDF document in terms of pages? Is it propperly tagged and tab-structured (if applicable)?
And how/where are you executing this script from (i.e. Document Level script, as a Mouse-Up Action button, a custom validation script) ?
Also, in the saving portion of your script, is it actually saving the document with the desired file name and desired folder (directory path) ?
Copy link to clipboard
Copied
Hi @nickl14077405 ,
Have you checked in the Developer's Console (CRT+J keyboard combination to open it) if the script is throwing any errors?
I get this error message.
Exception in line 20 of function top_level, script Batch:Exec
TypeError: this.getPageNth is not a function
20:Batch:Exec
How long is this PDF document in terms of pages? Is it propperly tagged and tab-structured (if applicable)?
This particular document is 88 pages but some documents are upwards of 3000. These are Clinical Study Reports that I am publishing.
And how/where are you executing this script from (i.e. Document Level script, as a Mouse-Up Action button, a custom validation script) ?
I am using action wizard as I do not know how to run it in the console.
Also, in the saving portion of your script, is it actually saving the document with the desired file name and desired folder (directory path) ? Generally yes. I have this set up in another action not using JS but I got curious and wanted to see if it were possible to run this as a script. Thank you for taking the time to reply.
By @ls_rbls
Copy link to clipboard
Copied
I don't know where you got that code from (AI?), but about half of it is made up and will not work in Acrobat.
Copy link to clipboard
Copied
Hello @try67 as I am very new to writing scripts I did get some help from ChatGPT which is probably frowned upon but I didn't know where to start.
Copy link to clipboard
Copied
Yes, I thought so. ChatGPT is very good in some things, but in the things it's not good, it's very good at faking it and making it appear like it knows what it's talking about, when in fact it doesn't at all...
Copy link to clipboard
Copied
Yes, ChatGPT's job is to merge together the info it finds, and sound convincing. Of course, if something is impossible it won't find the info, but it will still have a go, and it still sounds convincing. This has caused people much, much embarrassment and even legal consequences.
Copy link to clipboard
Copied
You can't run OCR with a script.
Copy link to clipboard
Copied
Ahh, this makes sense. I appreciate you letting me know.
Copy link to clipboard
Copied
You should use an Action containing:
1. OCR
2. run a JavaScript
3. Save as