Skip to main content
Participating Frequently
October 18, 2024
Question

ReferenceError: runOCRIfNeeded is not defined

  • October 18, 2024
  • 2 replies
  • 812 views

I want a js script that will first run Scan & OCR from Adobe Acrobat, and then run my custom script. Here is my script

function runOCRIfNeeded(doc) {
if (doc && !doc.isRecognized) {
app.execMenuItem("Scan:OCRRecognize");
app.alert("OCR completed");
}
}

function trustedRunOCR(oDoc) {
runOCRIfNeeded(oDoc);
}

that is in 

Applications/Adobe\ Acrobat\ 2020/JavaScripts/testScript.js

,I have restarted the application many times but everything is fine and I get the error
Reference error

This topic has been closed for replies.

2 replies

PDF Automation Station
Community Expert
Community Expert
October 18, 2024

The error means your call on the function is not defined.  Try adding the following line to the beginning of your script and restarting Acrobat.  If the file is in the right place you should see the popup when your restart.

app.alert("Script is running");

Participating Frequently
October 18, 2024

The script did not start, please tell me where it should be located .js file for mac.

Bernd Alheit
Community Expert
Community Expert
October 18, 2024

In the Javascript console execute:

app.getPath("app", "javascript");

 

try67
Community Expert
Community Expert
October 18, 2024

Where is the call for trustedRunOCR located? Also, why do you need that function, if all it does is call another function with the same parameter?

try67
Community Expert
Community Expert
October 18, 2024

PS. I'm assuming you've defined a doc-level variable called isRecognized at some point, as there's no built-in property with that name of the Document object.