---
title: "Extracting data from specific pages | Nutrient Java SDK"
canonical_url: "https://www.nutrient.io/guides/java/extraction/extract-data-from-specific-pages/"
md_url: "https://www.nutrient.io/guides/java/extraction/extract-data-from-specific-pages.md"
last_updated: "2026-07-10T00:00:00.000Z"
description: "Extract data from selected document pages using Nutrient Java SDK."
---

# Extracting data from specific pages

Long documents often carry the data you need on just a few pages — a cover sheet, a single invoice page, or one appendix. Restricting extraction to those pages skips the rest of the document, which cuts processing time and keeps the output focused on the content you care about.

The Nutrient Java SDK selects pages through the `pageRange` setting on the document's open settings. Extraction then runs only on the pages you list.

[Download sample](https://www.nutrient.io/downloads/samples/java/extract-data-from-specific-pages.zip)

## How Nutrient supports this workflow

`pageRange` is a 1-based range string applied before extraction. The SDK reads it once, resolves it to the matching pages, and processes only those — there's no need to split the document or post-filter the result.

The string accepts single pages and ranges, separated by commas or semicolons:

- `"5"` — page 5 only.

- `"1-3,5"` — pages 1, 2, 3, and 5.

- `"2;4;6"` — pages 2, 4, and 6.

- `""` (the default) or `"*"` — every page.

Parsing is lenient: it never throws. Page numbers outside the document are ignored rather than clamped, so a range that overshoots the last page selects only the pages that exist, and a value that matches no page extracts nothing.

## Complete implementation

This example extracts content from a chosen set of pages and writes it to JSON.

Specify a package name and create a new class:

```java

package io.nutrient.Sample;

```

Import the required classes from the SDK:

```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 ExtractDataFromSpecificPages {

```

Create the main method and declare thrown exceptions:

```java

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

```

Open the PDF with try-with-resources so the document closes automatically:

```java

        try (Document document = Document.open("input.pdf")) {

```

Set `pageRange` on the open settings to choose the pages to process. This example selects pages 1 through 3 and page 5:

```java

            document.getSettings().getOpenSettings().setPageRange("1-3,5");

```

Configure the Adaptive OCR engine, extract the selected pages as JSON, and write the result to `output.json`:

```java

            document.getSettings().getVisionSettings().setEngine(VisionEngine.AdaptiveOcr);

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

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

```

Only the pages named in `pageRange` reach the extraction pipeline. The page numbers in the result keep their original values, so a value extracted from page 5 still reports page 5 — selection narrows the work without renumbering the document.

## Handle errors

The Nutrient Java SDK uses exception handling for errors. The methods in this guide throw a `NutrientException` if a failure occurs. Use this exception to troubleshoot issues and implement error handling logic.

## Summary

The extraction flow has four steps:

1. Open the PDF document.

2. Set `pageRange` on the open settings to choose the pages.

3. Configure the Adaptive OCR engine and extract content as JSON with `Vision`.

4. Write the JSON output to a file.

You can download [this sample package](https://www.nutrient.io/downloads/samples/java/extract-data-from-specific-pages.zip) to run the example locally.
---

## Related pages

- [Applying OCR to a PDF document](/guides/java/extraction/apply-ocr-to-pdf.md)
- [Applying OCR to a PDF page](/guides/java/extraction/apply-ocr-to-pdf-page.md)
- [Classifying documents](/guides/java/extraction/classify-document.md)
- [Generating image descriptions using local AI](/guides/java/extraction/describe-image-with-local-ai.md)
- [Generating image descriptions using OpenAI](/guides/java/extraction/describe-image-with-openai.md)
- [Generating image descriptions using Claude](/guides/java/extraction/describe-image-with-claude.md)
- [Detecting document language](/guides/java/extraction/detect-document-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)
- [Extracting data from images using vision language models](/guides/java/extraction/extract-data-from-image-vlm.md)
- [Extracting form fields from images](/guides/java/extraction/extract-form-fields-from-image.md)
- [Extracting structured data from documents](/guides/java/extraction/extract-structured-data.md)
- [Generating extraction schemas](/guides/java/extraction/generate-extraction-schema.md)
- [Nutrient Java SDK extraction guides](/guides/java/extraction.md)
- [Extracting JSON data from a PDF document](/guides/java/extraction/json-data-extraction.md)
- [Extracting text from PDF documents](/guides/java/extraction/pdf-to-text.md)
- [Labeling form fields with a vision language model](/guides/java/extraction/label-form-fields-with-vlm.md)
- [Reading barcodes with vision extraction](/guides/java/extraction/read-barcodes-with-vision.md)
- [Extracting text from images](/guides/java/extraction/read-text-from-image.md)
- [Speeding up first ICR operation by predownloading models](/guides/java/extraction/speed-up-first-icr-by-downloading-requirements.md)
- [Searching document text](/guides/java/extraction/search-document-text.md)
- [Extracting text from multilingual images](/guides/java/extraction/read-text-from-image-multi-language.md)

