Overview
to_markdown() is the primary extraction function in PyMuPDF4LLM. It reads a document and returns its content as a Markdown string, preserving headings, lists, tables, code blocks, images, and reading order as closely as possible.
Common Options
Page Selection
Extract only specific pages by passing a list of zero-based page indices:Page Chunks
Return a list of per-page dictionaries instead of a single concatenated string. Each chunk includes the page’s Markdown text and associated metadata:Headers and Footers
PyMuPDF4LLM can detect and exclude repeating page headers and footers to keep the output clean:Images
To extract embedded images and reference them inline in the Markdown output:Tables
Table extraction is enabled by default. PyMuPDF4LLM renders detected tables as GitHub-flavoured Markdown tables:Full Example
A more complete call combining several options:For the full API signature including all parameters and return types, see the
to_markdown() API reference.Next Steps
Extract JSON
Bounding boxes and layout data for custom pipelines.
Extract Text
Get clean, plain text output.
Tables
Table extraction explained.
Saving Output
Write out data to file with pathlib.