> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pdf4llm.com/llms.txt
> Use this file to discover all available pages before exploring further.

# to_text()

> Extract document content as a plain text string, stripped of all Markdown formatting.

## Signature

```python theme={null}
pymupdf4llm.to_text(
    doc: str | pymupdf.Document,
    **kwargs
) -> str  | list[dict]
```

***

## Parameters

**doc** `str | pymupdf.Document` *required*

Path to the document file, or an already-opened `pymupdf.Document` instance. Supports PDF, XPS, eBooks, and — with PyMuPDF Pro — Office formats.

\*\***kwargs** `various`

Additional parameters are shared with `to_markdown()`. See the [to\_markdown() API reference](https://docs.pdf4llm.com/python/api/to_markdown) for details.

> [!TIP]
>
> For other parameters, see the shared [to\_markdown() API reference](https://docs.pdf4llm.com/python/api/to_markdown) which applies to all extraction functions.

***

## Returns

**str** `string`

When `page_chunks=False` (default). A single plain text string containing all extracted pages.

**list\[dict]** `list`

When `page_chunks=True`. A list of dictionaries, one per extracted page, each with the following keys:

| Key | Type | Description |
| - | - | - |
| `text` | `str` | Plain text content of the page |
| `metadata` | `dict` | Page metadata |

***

## Raises

| Exception | Condition |
| - | - |
| `FileNotFoundError` | `doc` is a path string that does not exist |
| `ValueError` | An index in `pages` is out of range for the document |
| `ImportError` | `ocr=True` or `force_ocr=True` but the `ocr` dependency is not installed |

***

## Examples

### Minimal

```python theme={null}
import pymupdf4llm

text = pymupdf4llm.to_text("document.pdf")
```

### Page chunks

```python theme={null}
chunks = pymupdf4llm.to_text("document.pdf", page_chunks=True)
for chunk in chunks:
    print(f"Page {chunk['metadata']['page']}: {len(chunk['text'])} chars")
    print(chunk['text'])
```

### Save to file

```python theme={null}
from pathlib import Path

text = pymupdf4llm.to_text("document.pdf")
Path("output.txt").write_text(text, encoding="utf-8")
```

***

## See Also

> [card] [Extract Text Guide](https://docs.pdf4llm.com/python/guides/extract-Text.md)
>
> Full guided overview.

> [card] [to\_markdown()](https://docs.pdf4llm.com/python/api/to_markdown)
>
> Markdown output preserving document structure.

> [card] [to\_json()](https://docs.pdf4llm.com/python/api/to_json)
>
> Structured output with bounding boxes and layout data.

{
/*
<Card title="Page Chunking" icon="layer-group" href="https://docs.pdf4llm.com/concepts/page-chunking">
  Full schema for page_chunks=True output.
</Card>
*/
}


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.