Welcome Guest! To enable all features, please Login or Register.

Notification

Icon
Error

Options
View
Last Go to last post Unread Go to first unread post
#1 Posted : Monday, March 6, 2017 10:06:40 AM(UTC)

Roberto  
Roberto

Groups: Registered, Tech Support, Administrators
Posts: 39

Thanks: 2 times
Was thanked: 3 time(s) in 3 post(s)

A number of times I've encountered requests for how to get started with our Java libraries in Eclipse. Here is a very short and simple tutorial for converting TIF to PDF using our OCR support.

Lets assume that you already have a new project set up in Eclipse. File->New->Project

new project

Next, you'll want to add the LEADTOOLS jar files to the project. You can right click on the project in the explorer and select Build Path -> Configure Build Path

build path

This should launch the properties dialog for the project, under the libraries tab you will want to select Add External JARs...

properties

Navigate to the LEADTOOLS Bin directory for Java (C:\LEADTOOLS 19\Bin\Java).

jars

For this example you will need the following Jars:

LEADTOOLS
CODECS
IMAGE.PROCESSING.COLOR
IMAGE.PROCESSING.CORE
IMAGE.PROCESSING.EFFECTS
DOCUMENTS
SVG
PDF
FORMS.DOCUMENT_WRITERS
FORMS.OCR

Now for the code. First and most importantly you need to explicitly load the libraries you will use and set your license. This is typically the part that stumps most people. I do the following:

Code:
	private static void loadLibraries() {
		try {
			Platform.setLibPath("C:\\LEADTOOLS 19\\Bin\\CDLLVC10\\x64");
			Platform.loadLibrary(LTLibrary.LEADTOOLS);
	         Platform.loadLibrary(LTLibrary.CODECS);
	         Platform.loadLibrary(LTLibrary.IMAGE_PROCESSING_COLOR);
	         Platform.loadLibrary(LTLibrary.IMAGE_PROCESSING_CORE);
	         Platform.loadLibrary(LTLibrary.IMAGE_PROCESSING_EFFECTS);
	         Platform.loadLibrary(LTLibrary.DOCUMENTS);
	         Platform.loadLibrary(LTLibrary.SVG);
	         Platform.loadLibrary(LTLibrary.PDF);
	         Platform.loadLibrary(LTLibrary.FORMS_DOCUMENT_WRITERS);
	         Platform.loadLibrary(LTLibrary.FORMS_OCR);
			String licenseFile = "C:\\LEADTOOLS 19\\Common\\License\\LEADTOOLS.LIC";
			String developerKey = "YOUR DEV KEY HERE";
			leadtools.RasterSupport.setLicense(licenseFile, developerKey);
		} catch (Exception e) {
			System.out.println(e.getMessage());
			e.printStackTrace();
		}

	}


You will need to provide your developer key where indicated.

Now the conversion.

Code:
	private static void convertToPDF(){
		try {
			String inputFile = "C:\\Users\\Public\\Documents\\LEADTOOLS Images\\OCR1.tif";
			String outputPath = "OUTPUT PATH HERE";
			//create instance of OCR engine
			OcrEngine ocrEngine = OcrEngineManager.createEngine(OcrEngineType.ADVANTAGE);
			//start the engine with default parameters
            ocrEngine.startup(null, null, null, null);
            //instance of our RasterCodecs to handle loading the image
            RasterCodecs codecs = new RasterCodecs();
            //load image
            RasterImage image = codecs.load(inputFile);        
            OcrDocument document = ocrEngine.getDocumentManager().createDocument();                  
            //create an OCR page from the image to be processed. In this case a default image shipped with the SDK
            OcrPage ocrPage = ocrEngine.createPage(image, OcrImageSharingMode.NONE);
            document.getPages().add(ocrPage);
            //tell the OCR engine to recognize the page
            ocrPage.recognize(null);
            System.out.println("PDF saved successfully here:\n" + outputPath);
            document.save(outputPath, DocumentFormat.PDF, null);
            
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}


Now call loadLibraries first (very important) followed by the conversion from your main().

Code:
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		loadLibraries();
		convertToPDF();
	}


And TADA! That should be it. Run the project and the results will be saved to the path you indicated.
Roberto Rodriguez
Developer Support Engineer
LEAD Technologies, Inc.

LEAD Logo
 

Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2020, Yet Another Forum.NET
This page was generated in 0.189 seconds.