This tutorial shows how to create a Java application that runs ICR to recognize handwritten text on a given image using the LEADTOOLS SDK.
|Summary||This tutorial covers how to use LEADTOOLS Recognition SDK technology in a Java application.|
|Completion Time||30 minutes|
|Eclipse Project||Download tutorial project (2 KB)|
|Development License||Download LEADTOOLS|
|Try it in another language|
Get familiar with the basic steps of creating a project by reviewing the Add References and Set a License tutorial, before working on the Recognize Handwritten Text From Images With ICR - Java tutorial.
Start with a copy of the project created in the Add References and Set a License tutorial. If that project is unavailable, follow the steps in that tutorial to create it.
The references needed depend upon the purpose of the project. References can be added by local
.jar files located at
For this project, the following references are needed:
For a complete list of which JAR files are required for your application, refer to Files to be Included with your Java Application
The License unlocks the features needed for the project. It must be set before any toolkit function is called. For details, including tutorials for different platforms, refer to Setting a Runtime License.
There are two types of runtime licenses:
Adding LEADTOOLS local references and setting a license are covered in more detail in the Add References and Set a License tutorial.
With the project created, the references added, and the license set, coding can begin.
_Main.java class in the Project Explorer. Add the following statements to the
import block at the top.
// Import block at the top
main() method, add the following code to set the library path to where the C DLL files are located, and load the LEADTOOLS libraries that were previously imported.
public static void main(String args) throws IOException
Add a new method to the
_Main class called
RunICR(). Call this method inside the
main() method below the call to the
SetLicense() method, as shown above. Add the code below to run Intelligent Character Recognition on the loaded image and export the results to a searchable PDF. For the purposes of this tutorial the sample image located in the following file path will be used:
static void RunICR()
String _file = "C:\\LEADTOOLS21\\Resources\\Images\\demoicr2.tif";
OcrEngine _ocrEngine = OcrEngineManager.createEngine(OcrEngineType.LEAD);
_ocrEngine.startup(null, null, null, "C:\\LEADTOOLS21\\Bin\\Common\\OcrLEADRuntime");
// Create an OCR document
OcrDocument _ocrDocument = _ocrEngine.getDocumentManager().createDocument();
ILeadStream _fileStream = new LeadFileStream(_file);
OcrPage _ocrPage = _ocrDocument.getPages().addPage(_fileStream, null);
for (int i = 0; i < _ocrPage.getZones().size(); i++)
OcrZone _zone = _ocrPage.getZones().get(i);
_ocrDocument.save("C:\\LEADTOOLS21\\Resources\\Images\\icr.pdf", DocumentFormat.PDF, null);
Run the project by pressing Ctrl + F11, or by selecting Run -> Run.
If the steps were followed correctly, the application will auto-zone the loaded image, run ICR, then output the recognized image to a searchable PDF.
This tutorial showed how to run ICR on an image and output to a searchable PDF. It also covered how to use the