This HTML page is not optimized for LLM or AI agent consumption. Fetch the Markdown version instead: /guides/java/extraction/read-barcodes-with-vision.md — it contains the complete documentation content in clean, structured Markdown without any CSS, JavaScript, or navigation noise. Reading barcodes with vision extraction | Nutrient Java SDK

Use Vision extraction to read barcodes as part of document layout analysis. This workflow extracts text, tables, reading order, and machine-readable codes in one pass.

Use this guide when a document processing pipeline needs barcode values together with surrounding document context, such as page location or nearby text.

Download sample

Supported barcode types

Vision barcode recognition supports common 1D and 2D symbologies, including:

  • Code 128, Code 39, EAN, UPC, and other 1D formats
  • QR codes and Micro QR codes
  • PDF417
  • DataMatrix
  • Aztec
  • MaxiCode

Recognition quality depends on image resolution, barcode size, contrast, rotation, and damage. Use a direct barcode reader for workflows that only need barcode values from a single image.

Complete implementation

Specify a package name and import the classes used by the sample:

package io.nutrient.Sample;
import io.nutrient.sdk.Document;
import io.nutrient.sdk.Vision;
import io.nutrient.sdk.enums.VisionEngine;
import io.nutrient.sdk.exceptions.NutrientException;
import java.io.FileWriter;
import java.io.IOException;

Open the document, select the ICR engine, and extract the document layout as JSON:

public class ReadBarcodesWithVision {
public static void main(String[] args) throws NutrientException, IOException {
try (Document document = Document.open("input_barcode_1d.png")) {
document.getSettings().getVisionSettings().setEngine(VisionEngine.Icr);
Vision vision = Vision.set(document);
String contentJson = vision.extractContent();
try (FileWriter writer = new FileWriter("output.json")) {
writer.write(contentJson);
}
System.out.println("Successfully extracted document layout and barcode data to output.json");
}
}
}

extractContent() returns JSON that includes detected barcode elements when the input contains supported barcodes. Each barcode element contains the decoded value and symbology information, together with its location in the document layout.

Markdown output

Markdown export surfaces barcode values as text in reading order. It doesn’t preserve the full coordinate data available in JSON.

Use JSON when downstream code needs page numbers, bounding boxes, decoded values, or symbology metadata.

Error handling

Vision API throws VisionException when extraction fails. VisionException derives from NutrientException, so catching NutrientException covers Vision-specific failures. Common causes include unreadable input files, unsupported image data, missing Vision resources, insufficient memory, or low-quality barcode images.

In production code:

  • Catch NutrientException.
  • Log the input file and Vision engine used for extraction.
  • Route low-quality scans to manual review or retry with a higher-resolution source image.

Summary

This workflow extracts barcode values through the Vision document layout pipeline. Use it when barcode values need to remain connected to the document structure, page location, and surrounding text.