---
title: "Extract specific PDF pages | Nutrient Python SDK"
canonical_url: "https://www.nutrient.io/guides/python/extraction/extract-data-from-specific-pages/"
md_url: "https://www.nutrient.io/guides/python/extraction/extract-data-from-specific-pages.md"
last_updated: "2026-08-10T00:00:00.000Z"
description: "How to extract data from selected PDF pages using Nutrient Python SDK."
---

# Extracting data from specific PDF 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 Python SDK selects pages through the `page_range` setting on the document's open settings. Extraction then runs only on the pages you list.

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

## How Nutrient supports this workflow

`page_range` 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.

Import the required Nutrient classes:

```python

from nutrient_sdk import Document
from nutrient_sdk import Vision
from nutrient_sdk import NutrientException
from nutrient_sdk import VisionEngine

```

Open the PDF with a Python [context manager](https://docs.python.org/3/reference/datamodel.html#context-managers). The context manager closes the document automatically:

```python

def main():
    try:
        with Document.open("input.pdf") as document:

```

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

```python

            document.settings.open_settings.page_range = "1-3,5"

```

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

```python

            document.settings.vision_settings.engine = VisionEngine.ADAPTIVE_OCR

            vision = Vision.set(document)
            content_json = vision.extract_content()

            with open("output.json", "w", encoding="utf-8") as f:
                f.write(content_json)

            print("Successfully extracted the selected pages to output.json")
    except NutrientException as e:
        print(f"Error: {e}")

if __name__ == "__main__":
    main()

```

Only the pages named in `page_range` 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 Python SDK uses exception handling for errors. The methods in this guide raise 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 `page_range` 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/python/extract-data-from-specific-pages.zip) to run the example locally.
---

## Related pages

- [Nutrient Python SDK extraction guides](/guides/python/extraction.md)
- [Applying OCR to a PDF page](/guides/python/extraction/apply-ocr-to-pdf-page.md)
- [Applying OCR to a PDF document](/guides/python/extraction/apply-ocr-to-pdf.md)
- [Classifying documents](/guides/python/extraction/classify-document.md)
- [Generating image descriptions using Claude](/guides/python/extraction/describe-image-with-claude.md)
- [Generating image descriptions using local AI](/guides/python/extraction/describe-image-with-local-ai.md)
- [Generating image descriptions using OpenAI](/guides/python/extraction/describe-image-with-openai.md)
- [Detecting document language](/guides/python/extraction/detect-document-language.md)
- [Extracting data from images using ICR](/guides/python/extraction/extract-data-from-image-icr.md)
- [Extracting data from images using OCR](/guides/python/extraction/extract-data-from-image-ocr.md)
- [Extracting data from images using vision language models](/guides/python/extraction/extract-data-from-image-vlm.md)
- [Extracting form fields from images](/guides/python/extraction/extract-form-fields-from-image.md)
- [Extracting structured data from documents](/guides/python/extraction/extract-structured-data.md)
- [Generating extraction schemas](/guides/python/extraction/generate-extraction-schema.md)
- [Extracting structured JSON data from PDF documents](/guides/python/extraction/json-data-extraction.md)
- [Labeling form fields with a vision language model](/guides/python/extraction/label-form-fields-with-vlm.md)
- [Opening password-protected PDFs](/guides/python/extraction/open-password-protected-pdf.md)
- [Extracting text from PDF documents](/guides/python/extraction/pdf-to-text.md)
- [Reading barcodes with vision extraction](/guides/python/extraction/read-barcodes-with-vision.md)
- [Extracting text from multilingual images](/guides/python/extraction/read-text-from-image-multi-language.md)
- [Extracting text from images](/guides/python/extraction/read-text-from-image.md)
- [Later, in another process — no document needed:](/guides/python/extraction/search-document-text.md)
- [Speeding up first ICR operation by predownloading models](/guides/python/extraction/speed-up-first-icr-by-downloading-requirements.md)
- [Split documents](/guides/python/extraction/split-document.md)

