Java code to extract text from image

The OCR technology is popular and valuable, especially for organizations moving away from paper. They need to extract important text from scanned documents and store it in business software. Healthcare, legal firms, and local government agencies are converting large records into searchable digital files.

If you need a strong yet easy OCR Java library for your project, you are in the right place. This article explains how to extract text from PNG images using Java. Scan receipts, passports, or capture a car number plate, save them as PNG files, and extract the text step by step.

The following points are covered:

Java PNG Text Extraction Library - Installation

In this section, we discuss how to install the Java PNG text extraction library. If you use Maven, add the following configuration to your pom.xml file.

<repository>
	<id>ConholdateJavaAPI</id>
	<name>Conholdate Java API</name>
	<url>https://releases.conholdate.com/java/repo</url>
</repository>        
<dependency>
	<groupId>com.conholdate</groupId>
	<artifactId>conholdate-total</artifactId>
	<version>23.6</version>
	<type>pom</type>
</dependency>

Then run:

mvn clean    
mvn install -U

For other Java frameworks, visit releases.conholdate.com.

Java Tutorial: Recognize and Extract Text from PNG

Learn how to extract text from a PNG image with our Java PNG text extraction library. Write only a few lines of code. Suppose we have a PNG image containing text like this:

Recognize and Extract Text from PNG using Java
Steps to extract text from a PNG using Java:

  1. Initialize an instance of the AsposeOcr class.
  2. Call the RecognizeImage(string fullPath) method to get the text.
  3. Print or save the extracted text.

The sample below shows how to extract text from a PNG using Java.

Extract Text from a Receipt Image using Java

Companies often need to process receipts for travel expenses, network fees, and other payments. Manually digitizing receipts is time‑consuming. This section shows how to automate receipt digitization with our OCR Java library.

Steps to extract text from a receipt image:

  1. Initialize an instance of AsposeOcr class.
  2. Create a ReceiptRecognitionSettings object.
  3. Set the language via ReceiptRecognitionSettings.Language.
  4. Call RecognizeReceipt(string, ReceiptRecognitionSettings) to get the text.
  5. Print or save the extracted text.

Java code to extract text from a receipt (PNG):

Extracting Text from a Passport Photograph in Java

Passport recognition is essential for border control, banking, and security. This section explains how to quickly recognize and extract text from a passport photo.

Steps to extract text from a passport PNG:

  1. Create an instance of AsposeOcr class.
  2. Initialize a PassportRecognitionSettings object.
  3. Set the language via PassportRecognitionSettings.Language.
  4. Call RecognizePassport(string, PassportRecognitionSettings) to read the text.
  5. Print or save the extracted text.

Code sample for extracting text from a passport PNG:

Java Guide: Read Text from a Vehicle Number Plate Picture

This section demonstrates how to extract text from a vehicle number plate image.

Steps to extract the plate text:

  1. Initialize an instance of AsposeOcr class.
  2. Create a CarPlateRecognitionSettings object.
  3. Set the language via CarPlateRecognitionSettings.Language.
  4. Call RecognizeCarPlate(string, CarPlateRecognitionSettings) to get the text.
  5. Print or save the extracted text.

Java code to extract text from a vehicle number plate PNG:

Get a Free License

You can obtain a free temporary license to try the API without evaluation limits.

Conclusion

We hope you now know how to recognize and extract text from PNG images in Java using our Java PNG text recognition and extraction library. The tutorial covered reading text from generic PNGs, receipts, passports, and vehicle number plates.

Visit the documentation to learn more about the Java Excel writer API.

Stay tuned at conholdate.com for regular updates.

Ask a Question

Submit your questions or queries on our forum.

See Also