# Extract text and tables (Preview) from a PDF for RAG and LLM pipelines

Source: https://pdfluent.com/how-to/extraction/

Pull position-aware text out of a PDF in Rust, Python, or Node.js, turn it into retrieval-ready chunks (Preview), and use the balanced tier (Preview) for table-aware extraction. Structured extraction is Preview.

**New in SDK 1.3.0:** `quality="auto"` is the default extraction tier: table structure, the document's own heading levels and OCR for pages without a text layer. Pass `quality="fast"` to keep the 1.2 output. On opendataloader-bench SDK 1.5.0 scores 0.9288 overall.* Auto needs a one-time model install, and OCR of scanned pages needs Tesseract on the machine. [Release post](https://pdfluent.com/blog/sdk-1-3-0/) · [Benchmark results](https://pdfluent.com/benchmarks/#odl-bench) *Not on its public leaderboard. SDK 1.3.0 results were submitted to the benchmark repository, PR #37 and #38. Measured with the benchmark's own harness on its 200 documents; macOS arm64 wheel built from the 1.5.0 release candidate; other engines as published in its README, not re-run by us. Full caveats on the benchmarks page.

## On this page

- Preview: extract Markdown and text blocks from a PDF in Rust, Python, and Node.js
- Preview: build retrieval chunks from extracted text
- Preview: table and layout-aware extraction for RAG Preview

## Install PDFluent

Install the SDK for Rust, Python, or Node.js. The install lines carry no version. The balanced tier (Preview) needs models installed once with the pdfluent CLI from the 1.1.0 release archives.

bash

```
# Rust
cargo add pdfluent@1.5.1

# Python
pip install pdfluent==1.5.0

# Node.js
npm install @pdfluent/node

# Models for the auto and balanced tiers
pdfluent models install layout tables
```

## Preview: extract Markdown and text blocks from a PDF in Rust, Python, and Node.js

A retrieval-augmented generation (RAG) pipeline needs more than a blob of text: knowing which page a passage came from, and roughly how it was laid out, makes later chunking and citation much easier. PDFluent's structured extraction returns Markdown, blocks, words with boxes, and chunks. Structured extraction is Preview: output quality is still improving and the API may change in a minor release.

Values move with their headings.

rust

```
use pdfluent::{ExtractOptions, PdfDocument, Quality};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let doc = PdfDocument::open("report.pdf")?;
    let markdown = doc.extract_markdown(&ExtractOptions::default())?;
    let blocks = doc.extract_blocks(&ExtractOptions::default())?;
    println!("{} blocks", blocks.len());
    // balanced: needs the ort-layout/ort-tables features and installed models
    let tables = doc.extract_markdown(&ExtractOptions::default().with_quality(Quality::Balanced))?;
    println!("{markdown}\n{tables}");
    Ok(())
}
```

1. Step 1 Rust: open the document and extract Markdown and blocks (Preview)PdfDocument::open takes a path. extract_markdown returns Markdown (Preview); extract_blocks returns a Vec<Block> (Preview). The default options use the fast tier, which runs the engine alone with no models. rust `*use pdfluent::{ExtractOptions, PdfDocument, Quality};**fn main() -> Result<(), Box<dyn std::error::Error>> {**let doc = PdfDocument::open("report.pdf")?;**let markdown = doc.extract_markdown(&ExtractOptions::default())?;**let blocks = doc.extract_blocks(&ExtractOptions::default())?;**println!("{} blocks", blocks.len());**Ok(())**}*`
2. Step 2 Python: extract Markdown, words, and chunks (Preview)Document is a context manager. extract_markdown returns Markdown (Preview); extract_words returns words with boxes (Preview); iter_chunks yields chunks with a.text attribute (Preview). Structured extraction is Preview. python `*from pdfluent import Document**from pdfluent.chunks import iter_chunks**with Document("report.pdf") as doc:**md = doc.extract_markdown() # fast tier, no models**words = doc.extract_words()**for chunk in iter_chunks(doc, mode="markdown"):**print(chunk.text)*`
3. Step 3 Node.js: extract Markdown and chunks (Preview)PdfDocument.open takes a buffer. extractMarkdown returns Markdown (Preview); iterChunks yields chunks with a.text attribute (Preview). Structured extraction is Preview. javascript `*const fs = require("node:fs");**const { PdfDocument, iterChunks } = require("@pdfluent/node");**const doc = PdfDocument.open(fs.readFileSync("report.pdf"));**const md = doc.extractMarkdown();**for (const chunk of iterChunks(doc, { mode: "markdown" })) {**console.log(chunk.text);**}*`

- Structured extraction is Preview: output quality is still improving and the API may change in a minor release. Plain-text extraction is not Preview.
- From SDK 1.3.0 the auto tier is the default: the balanced tier with the table model where the models are installed, the fast tier where they are not. The fast tier runs the engine alone, written in Rust, no models, and runs everywhere including WebAssembly.
- The balanced tier (Preview) runs a layout model and a table-structure model locally through ONNX Runtime 1.23.2. It is native only, never WebAssembly, and supports glibc Linux, macOS, and Windows. On musl Linux loading returns a typed ModelError. Balanced (Preview) is Markdown only: extract_markdown reads it, extract_blocks refuses it.
- Models install once, explicitly: pdfluent models install layout tables. From SDK 1.3.0, the Python package from PyPI installs the pdfluent command; in other setups it comes from the CLI archives on the release page. pdfluent models status shows what is installed and whether the pins verify. Nothing downloads automatically at run time. Without installed models (or, in Rust, the cargo features ort-layout / ort-tables), the balanced tier (Preview) refuses with MODEL_NOT_AVAILABLE.
- Pages: first_page (from zero) and page_count choose a window of the answer; the document is still read whole.
- In pdfluent 1.1.0, OCR is reachable from Python only: it is opt-in, off by default, and runs through a system tesseract binary on PATH (or PDFLUENT_TESSERACT), or through your own function passed as ocr_function=. From plain Rust, the pdfluent 1.1.0 crate does not reach tesseract.

Which binding should I use for a RAG ingestion pipeline?

Use whichever language your pipeline already runs in. Rust, Python, and Node.js all extract the same underlying text and position data.

Does extraction preserve reading order?

Blocks (Preview) are grouped by vertical proximity, which approximates reading order for single-column pages. Multi-column layouts and tables need extra handling — see the table extraction section below.

## Preview: build retrieval chunks from extracted text

Embedding models and vector stores work best on bounded chunks, not whole-page or whole-document strings. PDFluent provides iter_chunks for Python and iterChunks for Node.js, which yield chunks with a.text attribute. Structured extraction is Preview: output quality is still improving and the API may change in a minor release.

python

```
from pdfluent import Document
from pdfluent.chunks import iter_chunks

with Document("report.pdf") as doc:
    md = doc.extract_markdown()                        # fast tier, no models
    for chunk in iter_chunks(doc, mode="markdown"):
        print(chunk.text)
```

1. Step 1 Python: iterate chunks (Preview)iter_chunks takes a Document and a mode ("blocks" or "markdown") and yields chunks with a.text attribute. Structured extraction is Preview. python `*from pdfluent import Document**from pdfluent.chunks import iter_chunks**with Document("report.pdf") as doc:**for chunk in iter_chunks(doc, mode="markdown"):**print(chunk.text)*`
2. Step 2 Node.js: iterate chunks (Preview)iterChunks is exported from @pdfluent/node. It takes a document and an options object with mode: "markdown" and yields chunks with a.text attribute. Structured extraction is Preview. javascript `*const fs = require("node:fs");**const { PdfDocument, iterChunks } = require("@pdfluent/node");**const doc = PdfDocument.open(fs.readFileSync("report.pdf"));**for (const chunk of iterChunks(doc, { mode: "markdown" })) {**console.log(chunk.text);**}*`

- PDFluent does not include an embedding model or a vector store client. The chunks (Preview) produced by iter_chunks and iterChunks carry text; feed them to whatever embedding API and vector database your pipeline already uses.
- Structured extraction is Preview: output quality is still improving and the API may change in a minor release.
- For documents with running headers/footers repeated on every page, strip them before building chunks (Preview) — otherwise the same boilerplate line gets embedded once per page and can crowd out real content in retrieval.

What chunk size should I use?

This depends on your embedding model and how the LLM will use retrieved chunks (Preview), not on anything specific to PDFluent. Tune it against your own retrieval evaluation.

Can I chunk by table or by section instead of by character count?

Yes, if you have structural markers to split on. The balanced tier (Preview) returns Markdown (Preview) with headings and table cells, which you can use to split. See the next section.

## Preview: table and layout-aware extraction for RAG Preview

The fast tier returns Markdown, blocks, words with boxes, and chunks. The balanced tier (Preview) adds a layout model and a table-structure model for better table and structure detection. Structured extraction, including the balanced tier, is Preview: output quality is still improving and the API may change in a minor release.

rust

```
use pdfluent::{ExtractOptions, PdfDocument, Quality};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let doc = PdfDocument::open("report.pdf")?;
    let markdown = doc.extract_markdown(&ExtractOptions::default())?;
    let blocks = doc.extract_blocks(&ExtractOptions::default())?;
    println!("{} blocks", blocks.len());
    // balanced: needs the ort-layout/ort-tables features and installed models
    let tables = doc.extract_markdown(&ExtractOptions::default().with_quality(Quality::Balanced))?;
    println!("{markdown}\n{tables}");
    Ok(())
}
```

1. Step 1 Python: use the balanced tier (Preview)Pass quality="balanced" to extract_markdown. It needs installed models. Balanced (Preview) is Markdown only: extract_markdown reads it, extract_blocks refuses it. Structured extraction is Preview. python `*from pdfluent import Document**with Document("report.pdf") as doc:**md_tables = doc.extract_markdown(quality="balanced") # needs installed models*`
2. Step 2 Node.js: use the balanced tier (Preview)Pass { quality: "balanced" } to extractMarkdown. It needs installed models. Balanced (Preview) is Markdown only: extractMarkdown reads it, extractBlocks refuses it. Structured extraction is Preview. javascript `*const fs = require("node:fs");**const { PdfDocument, iterChunks } = require("@pdfluent/node");**const doc = PdfDocument.open(fs.readFileSync("report.pdf"));**const mdTables = doc.extractMarkdown({ quality: "balanced" });*`

- Structured extraction, including the balanced tier, is Preview: output quality is still improving and the API may change in a minor release.
- The balanced tier (Preview) runs a layout model and a table-structure model locally through ONNX Runtime 1.23.2. It is native only, never WebAssembly, and supports glibc Linux, macOS, and Windows. On musl Linux loading returns a typed ModelError.
- Models install once, explicitly: pdfluent models install layout tables. The pdfluent command comes from the CLI archives on the 1.1.0 release page. pdfluent models status shows what is installed and whether the pins verify. Nothing downloads automatically at run time. Without installed models (or, in Rust, the cargo features ort-layout / ort-tables), the balanced tier (Preview) refuses with MODEL_NOT_AVAILABLE.
- Model dir options: model_dir= / table_model_dir= (Python), modelDir / tableModelDir (Node), --model-dir (CLI), env PDFLUENT_MODEL_DIR.
- Table structure (A42, A43; measured 2026-10-17 on the held-out half): balanced (Preview) with the table model scores higher than Docling and pymupdf4llm on FinTabNet and PubTables-1M (TEDS), and higher than pymupdf4llm on ParseBench (record match).
- Office input to Markdown (Preview): in Python, pdfluent.extract_office(path_or_bytes, format="markdown") takes.docx,.pptx,.xlsx (routing by the file's content types, not the extension); format="docling" returns DoclingDocument JSON (Preview). HTML input is not part of this call.

Is the balanced tier available now?

Yes. It ships with PDFluent SDK 1.1.0. It is Preview: output quality is still improving and the API may change in a minor release.

What is the difference between the fast and balanced tiers?

From SDK 1.3.0 the auto tier is the default: the balanced tier with the table model where the models are installed, the fast tier where they are not. The fast tier runs the engine alone, written in Rust, no models, and runs everywhere including WebAssembly. The balanced tier (Preview) runs a layout model and a table-structure model locally through ONNX Runtime 1.23.2. It is native only, never WebAssembly, and supports glibc Linux, macOS, and Windows. Balanced (Preview) is Markdown only: extract_markdown reads it, extract_blocks refuses it.

How do I install the models for the balanced tier (Preview)?

Run pdfluent models install layout tables. From SDK 1.3.0, the Python package from PyPI installs the pdfluent command; in other setups it comes from the CLI archives on the release page. pdfluent models status shows what is installed and whether the pins verify. Nothing downloads automatically at run time.

## Related

[1.1.0 release](https://pdfluent.com/blog/sdk-1-1-0-structured-extraction/)[Docling comparison](https://pdfluent.com/benchmarks/text-extraction-vs-docling/)[Output formats](https://pdfluent.com/how-to/extraction-formats/)[Office to Markdown](https://pdfluent.com/how-to/office-markdown/)[PyMuPDF-style Python API](https://pdfluent.com/how-to/pymupdf-compat/)[Python docs](https://pdfluent.com/docs/python/)
