Skip to main content

Overview

ToMarkdown() is the primary extraction method in PDF4LLM. 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:
Extract every other page by building the page list with Linq:
For large documents, limiting extraction to the pages you need can dramatically reduce processing time — especially when OCR is involved.

Per-page chunks

Use LlamaMarkdownReader to return one document object per page instead of a single concatenated string. Each chunk includes the page’s Markdown text and associated metadata:

Headers and footers

PDF4LLM uses bounding box position to identify and exclude repeating page headers and footers. Filter them by building the page list and using ToJson to identify the margin bands, or exclude them at the chunking stage by filtering short leading and trailing lines from each page chunk. For documents with consistent header and footer heights, the most reliable approach is to filter blocks by their bounding box position using ParseDocument:

Images

To extract embedded images and reference them inline in the Markdown output:
Image references are embedded as standard Markdown image syntax:
See Image extraction for a full breakdown of image options.

Tables

Table extraction runs automatically. PDF4LLM renders detected tables as GitHub-flavoured Markdown tables:

Full example

A more complete call combining several options:
To save each page as a separate file, use LlamaMarkdownReader for per-page output:

For the full API signature including all parameters and return types, see the ToMarkdown() API reference.

Next steps

Extract JSON

Bounding boxes and layout data for custom pipelines.

Extract Text

Get clean, plain text output.