Convert JPG or PNG Image to XML with OCR in Java

Image to XML java

XML files are frequently used to structure data for storage and transport of data. Sometimes an image can contain some data or information that you may need to process further. You can easily convert a JPG or PNG image to XML format. This article explains how to convert the JPG or PNG image file to XML format with OCR programmatically in Java.

JPG or PNG Image to XML Converter with OCR in Java – API Installation

You can apply the optical character recognition technique over the images and several other file formats supported by Aspose.OCR for Java API. You may download the JAR file from the Downloads page or use the following Maven configurations in order to access the API from the Aspose Repository:

Repository

<repository>
    <id>AsposeJavaAPI</id>
    <name>Aspose Java API</name>
    <url>http://repository.aspose.com/repo/</url>
</repository>

Dependency

<dependency>
    <groupId>com.aspose</groupId>
    <artifactId>aspose-ocr</artifactId>
    <version>22.5</version>
</dependency>

Convert Image to XML Data with OCR Programmatically in Java

You can convert a JPG or PNG image to XML with OCR operations by following the steps below:

  1. Initialize an object of the AsposeOCR class.
  2. Create a RecognitionResult class object to recognize the image.
  3. Print the extracted XML data.

The following code sample explains how to convert an image to XML data programmatically in Java:

Convert JPG or PNG Image to an XML File in Java

You can convert an image to XML format and write the converted data to a file. The steps below elaborate the process to convert a JPG or PNG image to an XML file:

  1. Create an object of the AsposeOCR class.
  2. Initialize an instance of the RecognitionSettings class and recognize the image with OCR.
  3. Write the output file as an XML file.

The code below demonstrates how to convert a JPG or PNG image to XML programmatically in Java:

Get Free API License

You may test all the features of the API without any evaluation limitations. Simply request a free temporary license.

Conclusion

In this article, you have learned how to convert a JPG or PNG image to XML data or a file with OCR programmatically in Java. Furthermore, different features and use cases are covered under different chapters in the documentation section. Please feel free to write to us at the forum in case of any queries.

See Also

Convert Image to Excel with OCR in Java