Take the following steps to start a project and to add some code that performs OCR on an image using Java:
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.
Save in Notepad to XML with any name such as 'LEAD_OCR_Service.xml' in a directory of your choice.
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.*;
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.ADVANTAGE);
port.recognize(parameters);
}
catch (Exception ex)
{
// TODO handle custom exceptions here
}
Notes:
Products |
Support |
Feedback: How to Consume LEADTOOLS WCF in Java Netbeans |
Introduction |
Help Version 19.0.2017.6.21
|
Raster .NET | C API | C++ Class Library | JavaScript HTML5
Document .NET | C API | C++ Class Library | JavaScript HTML5
Medical .NET | C API | C++ Class Library | JavaScript HTML5
Medical Web Viewer .NET
Your email has been sent to support! Someone should be in touch! If your matter is urgent please come back into chat.
Chat Hours:
Monday - Friday, 8:30am to 6pm ET
Thank you for your feedback!
Please fill out the form again to start a new chat.
All agents are currently offline.
Chat Hours:
Monday - Friday
8:30AM - 6PM EST
To contact us please fill out this form and we will contact you via email.