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

Adding a button to the toolbar to OCR the open document

Acrobaddy
Registered: Mar 18 2011
Posts: 2

I don't know why this is kicking me in the butt. I would like to add a button to the toolbar that will OCR the open document when it's clicked. That's it.
 
It should not be document specific and should be available to any document open in Acrobat.
 
Please be specific as to where I should put the Java code, how I should save it, etc. Part of the problem I am having is that the code I am using is specific to the document and I need the button to be global (i.e. to every open document.)
 
I am using Acrobat 9 pro on windows 7.
 
Thanks.

My Product Information:
Acrobat Pro 9.4.2, Windows
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1875
What code are you currently using?
Acrobaddy
Registered: Mar 18 2011
Posts: 2
var loadATBToolButton = app.trustedFunction( function () {
if ( typeof atbtoolbuttons == "undefined" )
atbtoolbuttons = true;
else {
if (!atbtoolbuttons) {
app.removeToolButton("atbToolButton1");
app.removeToolButton("atbToolButton2");
atbtoolbuttons = true;
return;
}
}
if ( atbtoolbuttons ) {
app.beginPriv();
app.addToolButton({
cName: "atbToolButton1",
cExec: "app.alert('button 1');",
cTooltext: "My toolbar button 1",
nPos: 0
});

app.addToolButton({
cName: "atbToolButton2",
cExec: "app.alert('button 2')",
cTooltext: "My toolbar button 2",
nPos: 0
});
app.endPriv();
}
})

loadATBToolButton();
UVSAR
Expert
Registered: Oct 29 2008
Posts: 1357
There's no JavaScript access to the OCR systems in Acrobat, so the most you could get your button to do is trigger a menu item and open the dialog box (in Acrobat 9 only - there's no such menu in Acrobat X).

You also need to either pass a text label via the cLabel property, or load an icon graphic stream, when creating a button or nothing will happen. Read the examples in the Acrobat SDK.

Jack Sparrow
Registered: Dec 7 2011
Posts: 2
Here is a working solution.

Place this code in a file with the name of your choosing; mine was “OCR_Button.js “. Another option, place the code in the config.js file. Then place the file in the location of the folder level scripts and start Acrobat Pro. The button labeled “OCR” will show up on the “Add-on” toolbar.

// Code to get folder location:
//app.getPath("user","javascript");
//
// Results with Location of folder level scripts:
// /xxxx/xxxx/xxxxx/Adobe/Acrobat/9.0/JavaScripts

app.addToolButton({
cName: "OCR",
cExec: "OCR_Document()",
cTooltext: "Recognize Text using OCR",
//cEnable: true, //Button is active all the time.
cEnable: "event.rc = (app.doc != null);",
nPos: 0,
cLabel: "OCR"
});

// Recognize Text Function
var OCR_Document = app.trustedFunction(
function(cPath)
{
app.beginPriv();
this.app.execMenuItem('Cpt:CapturePages');
app.endPriv();
}
);

Jack