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.
Nutrient .NET SDK selects pages through the page range setting on the document’s open settings. Extraction then runs only on the pages you list.
Download sampleHow Nutrient supports this workflow
The 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 Nutrient namespace:
using Nutrient;Open the PDF document inside a using statement(opens in a new tab). The using statement closes the document automatically:
try{ using Document document = Document.Open("input.pdf");Set the page range on the open settings to choose the pages to process. This example selects pages 1 through 3 and page 5:
document.Settings.OpenSettings.PageRange = "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:
document.Settings.VisionSettings.Engine = VisionEngine.AdaptiveOcr;
Vision vision = Vision.Set(document); string contentJson = vision.ExtractContent();
File.WriteAllText("output.json", contentJson);
Console.WriteLine("Successfully extracted the selected pages to output.json");}catch (NutrientException e){ Console.Error.WriteLine($"Error: {e.Message}"); Environment.Exit(1);}Only the pages named in the 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
Nutrient .NET 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:
- Open the PDF document.
- Set the page range on the open settings to choose the pages.
- Configure the Adaptive OCR engine and extract the selected pages as JSON with
Vision. - Write the JSON output to a file.
You can download this sample package to run the example locally.