Skip to main content

Overview

ToText() extracts the content of a document as a plain text string — no Markdown syntax, no bounding boxes, no metadata. It’s the simplest output format and the right choice when your downstream tool doesn’t need formatting or structure, just the words.

When to use plain text

If you’re feeding content into an LLM and document structure matters — headings, lists, tables — use ToMarkdown() instead. LLMs handle Markdown well and the added structure improves output quality.

Page selection

Extract only the pages you need:

Per-page chunks

Use LlamaMarkdownReader to return one document object per page instead of a single concatenated string. Each chunk includes the page’s plain text and a metadata dictionary with the page number and source file path:
Each chunk’s Text property contains the plain Markdown for that page. For plain text specifically, strip Markdown syntax after loading, or call ToText per page using the pages parameter:

Saving to a file

Write the output to a .txt file:
To save each page as a separate file:

OCR behaviour

Like ToMarkdown(), ToText() can invoke Tesseract OCR on pages that contain no selectable text. Pass useOcr: true to enable it:
See OCR for a full walkthrough of Tesseract installation, language codes, and patterns for mixed documents.
For the full API signature, see the ToText() API reference.

Next steps

Extract Markdown

Preserve structure and formatting for LLM pipelines.

Extract JSON

Access bounding boxes and layout data for custom pipelines.

OCR

Control OCR behaviour and language configuration.