These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

OCR script not working

Milton Snider
Registered: Feb 2 2009
Posts: 5

Please tell me why the button created from the following script does not work. The button is created and displayed but nothing happens when clicked. Also please point me to where I can find out how to make this button display for all documents in my toolbar.

app.addToolButton({
cName: "OCR",
cExec: "app.execMenuItem('Cpt:CapturePages')",
cTooltext: "Recognize Text using OCR",
cEnable: true,
nPos: 0,
cLabel: "OCR"
});

My Product Information:
Acrobat Pro 9.2, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
The app.execMenuItem() function is running in the context of the currently open document, as it should since this is what you want to OCR. However, since version 8 Acrobat has restricted the menu items that can be run in a document context. You can see this by adding a button to a PDF and selecting "Execute a Menu Item" as the action. I can guarentee you that you won't find the OCR items on the list.

In order to run this menu item and to create a toolbar button that is availible to all documents you need to do two things. First the code has to be in a Folder Level Script, and second, the execMenuItem function has to be run from a privileged context. Here are some articles that cover these topics:

http://www.acrobatusers.com/tutorials/2006/folder_level_scripts
http://www.acrobatusers.com/tutorials/2008/10/using_trusted_functions

Here's a blog post that discusses the new security features and in Particular the menu Item problem
http://www.acrobatusers.com/blogs/thomp/security-makes-life-difficult-everyone-not-just-you

This article shows how to make a button that runs a trusted function
http://www.acrobatusers.com/tutorials/2007/10/apply_security_with_js

This article show how to create a toolbar button that runs a menu item using the AcroButtons tool,
Although it was written before Acrobat 8 and doesn't use a trustedFunction
http://www.windjack.com/resources/howto/WJHowTo_MenuButton.php

Here's where you can get a free tool for displaying the Language Independant Menu Item Names
(and many other tools):
http://www.pdfscripting.com/public/65.cfm


Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

Milton Snider
Registered: Feb 2 2009
Posts: 5
Ok, I'll read your suggested articles. I guess I looked at the wrong list. Here is the list where I found the menu commands. Cpt:CapturePages is def in the list.
Thanks for the articles.
Milton
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Please don't paste stuff like that into the forum. It's totally unnecessary and makes reading the posts difficult.

There's nothing wrong with your menu item name, 'Cpt:CapturePages' is a valid menu item name and if you run it from the console window it will work as expected. That's not the issue. The problem is the context from which it is being run in your code.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script