1. Start NetBeans IDE 6.1.
2. Choose File-> New Project... from the menu.
3. In the New Project dialog box, choose "Java" in the Categories list, and choose "Java Application" in the Projects list. And press 'Next'.
4. Type the project name as "OCRImage" in the Project Name field, and if desired type a new location for your project or select a directory
using the Browse button. Then choose 'Finish'.
5. From the 'Projects' window, Right-Click on the Project 'OCRImage' icon and choose 'New'-> 'Web Service Client'.
6. The 'New Web Service Client' wizard will appear. Choose 'WDSL URL' as the WDSL file location. Specify the URL as:
http://localhost:8080/LeadtoolsServicesHost/OcrService.svc
7. Set the Proxy options using the 'Proxy' button. And press 'Finish'.
8. Open 'Notepad' and Paste the following into it:
[XML]
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <bindings wsdlLocation="[PATH]\OcrService.svc.wsdl" xmlns="http://java.sun.com/xml/ns/jaxws"> <bindings node="wsdl:definitions/wsdl:types/xs:schema" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"> <globalBindings xmlns="http://java.sun.com/xml/ns/jaxb"> <generateElementProperty xmlns="http://java.sun.com/xml/ns/jaxb/xjc">false</generateElementProperty> </globalBindings> </bindings> </bindings>
Important Note: To get the [PATH], go to the project 'OCRImage' directory => 'xml-resources' => 'web-service-references' => 'OcrService.svc'=> 'wsdl' => 'localhost:8080' => 'LeadtoolsServicesHost' then copy the Path of the file and replace [PATH] with it.
9. Save in Notepad to XML with any name such as 'LEAD_OCR_Service.xml' in a directory of your choice.
10. In the 'Projects' window of the 'OCRImage' project, browse to 'Web Service References', Right-Click on the 'OCRService.svc' and choose 'Edit Web Service Attributes'.
11. In the 'WSDL Customization Tab', expand 'External Binding Files' and Press 'Add'. Press yes, locate the 'LEAD_OCR_ Service.xml' and choose OK.
12. In 'Main.java' add the following code after 'package ocrimage;'
[Java]
import datacontracts.document.services.leadtools._2009._01.DocumentConvertOptions; import datacontracts.document.services.leadtools._2009._01.OcrDocumentFormatType; import datacontracts.document.services.leadtools._2009._01.OcrEngineType; import datacontracts.services.leadtools._2009._01.FileBinaryData; import servicecontracts.document.services.leadtools._2009._01.*;
13. Add the following code in the Main function:
[Java]
try { // Call Web Service Operation OcrService service = new OcrService(); IOcrService port = service.getBasicHttpBindingIOcrService(); // TODO initialize WS operation arguments here FileBinaryData sourceFile = new FileBinaryData(); sourceFile.setFileName("\\\\MyMachine\\SharedFolder\\OCR1.TIF"); FileBinaryData destData = new FileBinaryData(); destData.setFileName("\\\\MyMachine \\SharedFolder\\OCR1.txt"); DocumentConvertOptions convertOptions = new DocumentConvertOptions(); convertOptions.setFormat(OcrDocumentFormatType.ASCII_TEXT); convertOptions.setSource(sourceFile); convertOptions.setDestination(destData); RecognizeRequest parameters = new RecognizeRequest(); parameters.setConvertOptions(convertOptions); parameters.setEngineType(OcrEngineType.PLUS); port.recognize(parameters); } catch (Exception ex) { // TODO handle custom exceptions here }
Notes:
- MyMachine is the name of the Machine you are running the application from if you are performing an OCR on a disk file.
- The OCR Service must have write/read access to 'MyMachine'
14. Compile and Run the application.