Overview
By default, PyMuPDF4LLM processes every page in a document. Thepages parameter lets you specify exactly which pages to extract — as a list of zero-based page indices. It is supported by to_markdown(), to_json(), and to_text().
Zero-Based Indexing
Page numbers in PyMuPDF4LLM are zero-based — the first page of a document is page0, the second is page 1, and so on.
Common Patterns
First N Pages
Last N Pages
A Specific Range
Non-Contiguous Pages
Every Other Page
Getting the Page Count
Use PyMuPDF directly to inspect a document’s page count before building yourpages list:
Page Selection with Page Chunks
When usingpage_chunks=True, the returned list will only contain chunks for the pages you specified. Chunk metadata preserves the original page number from the document:
Page Selection with to_json() and to_text()
Thepages parameter works identically across all three extraction functions:
Processing a Document in Batches
For very large documents, you may want to 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 to_markdown(), to_json(), and to_text(). 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 to_markdown() with all common options.
Extract JSON
Bounding boxes and layout data for custom pipelines.
OCR
Control automatic OCR behaviour and adaptors.