Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

ReferenceError: runOCRIfNeeded is not defined

New Here ,
Oct 18, 2024 Oct 18, 2024

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

TOPICS
Modern Acrobat , PDF , PDF forms , Scan documents and OCR
844
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 18, 2024 Oct 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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 18, 2024 Oct 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 18, 2024 Oct 18, 2024

I have testPlugin.js in Applications/Adobe\ Acrobat\ 2020/JavaScripts/

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 18, 2024 Oct 18, 2024

trustedRunOCR located in javascript debugger.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 18, 2024 Oct 18, 2024

I can remove if(doc && doc.isRecognized) check but the problem is that console can't find the function that is in the .js file.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 18, 2024 Oct 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");

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 18, 2024 Oct 18, 2024

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 18, 2024 Oct 18, 2024

In the Javascript console execute:

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

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 18, 2024 Oct 18, 2024

I put it in the right place now the script is working, but it gives a new error
InvalidArgsError: Invalid arguments.
App.execMenuItem:7:Doc ProcessPDFButton:Exec 😞

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 18, 2024 Oct 18, 2024

I don't see a menu item with this name. How did you come by it?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 18, 2024 Oct 18, 2024
LATEST

That menu item does not exist.  Run the following script in the console:

app.listMenuItems();

Then copy what it returns to a text editor and search OCRRegcognize.  The menu item names aren't always what you think they are.  Also search Scan and if found, look inside the array for a potential name.  You can test in the console by running:

app.execMenuItem("TheNameToTest");

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines