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, November 7, 2016 11:57:51 AM(UTC)

Aaron  
Aaron

Groups: Registered, Tech Support, Administrators
Posts: 71

Was thanked: 4 time(s) in 3 post(s)

The below sample code uses the LEADTOOLS 19 PDF SDK for Linux in Java, and shows how to extract the text from a vector based PDF file without having to rasterize then OCR the PDF.

The sample code uses the ParsePages method to parse the vector objects in the PDF file:

https://www.leadtools.co...document~parsepages.html

Then the code iterates over each PDFObject and prints out the text if the PDFObject is a text object.

Code:
public class PDFDocumentExtractPages {
	public static void main(String args[]) {
		if (loadLibraries()) {
			// Load the PDF file
			PDFDocument doc = new PDFDocument("<Path to the LEADTOOLS directory>/LEADTOOLS19/Images/leadtools.pdf");
			// Parse the PDFDocument to get all the objects
			doc.parsePages(PDFParsePagesOptions.OBJECTS.getValue(), 1, -1);
			// Loop over each page in the PDFDocument
			for (PDFDocumentPage page : doc.getPages()) {
				if (page.getObjects() != null) {
					// Loop over each object in the page
					for (PDFObject obj : page.getObjects()) {
						// If the PDF object is a text object then print out the text
						if (obj.getObjectType() == PDFObjectType.TEXT) {
							System.out.print(obj.getCode());
						}
					}
				}
			}
		}
	}
	
	public static boolean loadLibraries() {
		try {
			// Set the path to the libs
			Platform.setLibPath("<Path to the LEADTOOLS directory>/LEADTOOLS19/Bin/Lib/x64");
			
			// Load in the necessary libraries
			Platform.loadLibrary(LTLibrary.LEADTOOLS);
	        Platform.loadLibrary(LTLibrary.IMAGE_PROCESSING_CORE);
	        Platform.loadLibrary(LTLibrary.SVG);
	        Platform.loadLibrary(LTLibrary.PDF);
	        Platform.loadLibrary(LTLibrary.DOCUMENTS);
			
			String licensePath = "Path to the developer license file";
			String developerKey = "Developer key";
			
			// Set your license
			RasterSupport.setLicense(licensePath, developerKey);
			
			if(RasterSupport.getKernelExpired()) {
				System.out.println("License NOT Set Successfully");
				return false;
			}
			else {
				System.out.println("License Set Successfully");
				return true;
			}
		}
		catch(Exception ex) {
			ex.printStackTrace();
			return false;
		}
	}
}
Aaron Brasington
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-2019, Yet Another Forum.NET
This page was generated in 0.111 seconds.