Skip to main content

Overview

By default, PDF4LLM processes every page in a document. The pages parameter lets you specify exactly which pages to extract — as a List<int> of zero-based page indices. It is supported by ToMarkdown(), ToJson(), and ToText().

Zero-based indexing

Page numbers in PDF4LLM are zero-based — the first page of a document is page 0, the second is page 1, and so on.
Passing a page index that doesn’t exist in the document will raise an exception. Always check the document’s page count (doc.PageCount) before constructing a dynamic page list.

Common patterns

First N pages

Last N pages

A specific range

Non-contiguous pages

Every other page


Getting the page count

Open a Document to inspect the page count before building your pages list:

Page selection with per-page chunks

When using LlamaMarkdownReader, the returned list will only contain chunks for the pages you specify if you pre-filter the results. Each chunk’s ExtraInfo preserves the original page number from the document:
The page value in ExtraInfo reflects the original document page number, not the position in the returned list. Page 4 in the document is always reported as 4, regardless of how many pages were skipped.

Page selection with ToJson() and ToText()

The pages parameter works identically across all three extraction methods:

Processing a document in batches

For very large documents, process pages in batches to manage memory usage:

Skipping blank or cover pages

Combine page selection with a quick content check to skip pages that return no meaningful text:

The pages parameter is supported by ToMarkdown(), ToJson(), and ToText(). For full API signatures see the API reference.

Next steps

Saving Output

Write extracted pages to .md, .json, and .txt files.

Extract Markdown

Full walkthrough of ToMarkdown() with all common options.

Extract JSON

Bounding boxes and layout data for custom pipelines.

OCR

Process scanned pages with Tesseract OCR.