---
title: "Extracting text from images | Nutrient Java SDK"
canonical_url: "https://www.nutrient.io/guides/java/extraction/read-text-from-image/"
md_url: "https://www.nutrient.io/guides/java/extraction/read-text-from-image.md"
last_updated: "2026-05-30T02:20:01.341Z"
description: "Extract text from images using OCR with Nutrient Java SDK."
---

# Extracting text from images

In modern business operations, converting image-based text into searchable, editable digital content is a critical step in workflow automation. Organizations often face the challenge of manually transcribing information from scanned documents and photographs — a process that is time-consuming and prone to human error.

This sample demonstrates the technical foundation for automated text extraction from images using Nutrient Java SDK. It showcases how businesses can transform static visual content into actionable digital text. This capability supports complex document processing workflows, including:

- Search functionality — Making scanned documents searchable.

- Accessibility compliance — Supporting screen readers and text-to-speech.

- Automated data entry — Eliminating manual transcription in form processing.

Whether you’re digitizing historical archives or processing high volumes of form submissions, the ability to reliably extract text from images enables automation strategies that maintain accuracy and efficiency across diverse operational contexts.

## Streamlining document workflows with our Java SDK

Developers can implement this feature by adding just a few lines of code to their applications. Nutrient Java SDK integrates Adaptive OCR text extraction directly, eliminating the requirement for external tools or complex setups. Whether you’re building a document processing pipeline or adding extraction functionality to a web application, the SDK provides a reliable and efficient solution right out of the box.

## Preparing the project

Specify a package name and create a new class for the task:

```java

package io.nutrient.Sample;

```

Import the required modules from Nutrient Java SDK. It’s recommended to specify the actual classes, though wildcards are supported:

```java

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;

public class ReadTextFromImage {

```

Create the main function and specify the potential exceptions. In a production environment, you may choose to wrap these in a try-catch block for custom error handling:

```java

    public static void main(String[] args) throws NutrientException, IOException {

```

With the Java environment ready, you can now focus on the SDK-specific implementation.

## Loading and processing the image

Open the image file and configure the vision API to use the Adaptive OCR engine for text extraction:

```java

        try (Document document = Document.open("input.png")) {
            // Configure OCR engine for text extraction
            document.getSettings().getVisionSettings().setEngine(VisionEngine.AdaptiveOcr);

```

The `Document.open` method loads the image into memory and prepares it for extraction. In this sample, `VisionEngine.AdaptiveOcr` runs an Adaptive OCR pipeline. For image inputs like this one, it behaves like a fast OCR extraction mode.

## Executing text recognition

Create a vision instance and extract the text content. The vision API analyzes the image structure, identifies text regions, and converts visual characters into structured digital text:

```java

            Vision vision = Vision.set(document);
            String contentJson = vision.extractContent();

```

The `extractContent` method performs the extraction and returns a JSON structure containing recognized text with positioning information.

## Saving extracted results

Write the extracted content to a JSON file for use in downstream applications:

```java

            try (FileWriter writer = new FileWriter("output.json")) {
                writer.write(contentJson);
            }
        }
    }
}

```

This creates a JSON file containing all recognized text from the image. The structured output includes word-level bounding boxes and text content ready for:

- Search indexing

- Database storage

- Content management workflows

## Understanding the output

The `extractContent` method returns a JSON structure that provides comprehensive metadata for the processed document. This structure includes:

- **Text content** — The full string of extracted text from the document.

- **Bounding boxes** — The precise (x, y) coordinates and dimensions (width/height) of text regions on the page.

- **Word-level data** — Detailed information for individual words, including their specific coordinates and confidence scores.

## Error handling

Nutrient Java SDK handles errors with exception handling. The methods presented in this guide throw a `NutrientException` in case of failure. This helps with troubleshooting and implementing error handling logic within your Java application.

## Conclusion

That’s all it takes to extract text from an image using Adaptive OCR. The extracted content is ready for integration with search systems, accessibility tools, or automated data processing workflows. You can also download [this ready-to-use sample package](https://www.nutrient.io/downloads/samples/java/read-text-from-image.zip), fully configured to help you dive into Nutrient Java SDK and explore seamless text extraction capabilities.
---

## Related pages

- [Applying OCR to a PDF page](/guides/java/extraction/apply-ocr-to-pdf-page.md)
- [Applying OCR to a PDF document](/guides/java/extraction/apply-ocr-to-pdf.md)
- [Generating image descriptions using Claude](/guides/java/extraction/describe-image-with-claude.md)
- [Generating image descriptions using local AI](/guides/java/extraction/describe-image-with-local-ai.md)
- [Extracting data from images using vision language models](/guides/java/extraction/extract-data-from-image-vlm.md)
- [Extracting JSON data from a PDF document](/guides/java/extraction/json-data-extraction.md)
- [Speeding up first ICR operation by predownloading models](/guides/java/extraction/speed-up-first-icr-by-downloading-requirements.md)
- [Extracting text from multilingual images](/guides/java/extraction/read-text-from-image-multi-language.md)
- [Extracting data from images using ICR](/guides/java/extraction/extract-data-from-image-icr.md)
- [Extracting data from images using OCR](/guides/java/extraction/extract-data-from-image-ocr.md)
- [Generating image descriptions using OpenAI](/guides/java/extraction/describe-image-with-openai.md)
- [Nutrient Java SDK extraction guides](/guides/java/extraction.md)

