Skip to main content
Glama
README.md
# pdfsift

<!-- mcp-name: io.github.vitorsilverio/pdfsift -->

**PDF → structured Markdown, built for LLM agents.** Headings, paragraphs, lists and tables in reading order, with running headers, footers and line-end hyphens removed. Plain heuristics over what the PDF already contains: no AI model, no OCR, no network.

> **Status: stable (1.0.0).** The output format is frozen ([docs/usage.md](docs/usage.md)); it changes only in a major version. Text, headings, lists, tables, images, emphasis, links, footnotes and block quotes work well on the test corpus; `info`, `toc`, `--json` and an MCP server make it easy for agents to read only what they need (see [Limitations](#limitations) and the [changelog](CHANGELOG.md)).

```console
$ pdfsift chrome.pdf          # two-column test document (in Portuguese)
<!-- pdfsift: source=chrome.pdf pages=1-3/3 -->
<!-- page: 1 -->
# Colunas Estreitas, Hifenização e Ligaduras

Projeto pdfsift

Resumo

Este documento é composto em duas colunas estreitas para forçar a hifenização no fim das linhas, …

# Introdução

A extração de texto de um arquivo PDF parece simples até o primeiro documento em duas colunas. …
```

## Install

Every channel ships the [PDFium](https://pdfium.googlesource.com/pdfium/) library (the PDF engine of Chrome) next to the executable; nothing is downloaded at run time.

| Channel | Command |
|---|---|
| npm (no install) | `npx @vitorsilverio/pdfsift file.pdf` |
| npm (global) | `npm install -g @vitorsilverio/pdfsift`, then `pdfsift file.pdf` |
| PyPI (no install) | `uvx pdfsift file.pdf` or `pipx run pdfsift file.pdf` |
| PyPI (global) | `uv tool install pdfsift` or `pipx install pdfsift` |
| Homebrew | `brew install vitorsilverio/tap/pdfsift` |
| Shell (Linux, macOS) | `curl -LsSf https://github.com/vitorsilverio/pdfsift/releases/latest/download/install.sh \| sh` |
| PowerShell (Windows) | `irm https://github.com/vitorsilverio/pdfsift/releases/latest/download/install.ps1 \| iex` |
| Archives | `.tar.xz`/`.zip` with SHA-256 and build attestations on [GitHub Releases](https://github.com/vitorsilverio/pdfsift/releases) |
| Cargo | `cargo install pdfsift`, then get PDFium (below) |

Prebuilt for Linux (x86_64, aarch64; glibc 2.34+ for the archives, 2.17+ for the PyPI wheels), macOS (x86_64, arm64) and Windows (x86_64, arm64). No musl/Alpine build yet. On npm the package is scoped (`@vitorsilverio/pdfsift`, because the registry rejects the unscoped name as too close to `pdfkit`); the installed command is still `pdfsift`.

**PDFium with `cargo install`:** crates.io carries only the source, so download `pdfium-<platform>.tgz` from [bblanchon/pdfium-binaries `chromium/8179`](https://github.com/bblanchon/pdfium-binaries/releases/tag/chromium%2F8179) and put the library (`libpdfium.so`, `libpdfium.dylib` or `pdfium.dll`) next to the `pdfsift` executable, or point `PDFSIFT_PDFIUM` at it. If it is missing, pdfsift says where it looked.

## Usage

```sh
pdfsift info file.pdf             # run first: pages, scanned pages, size in tokens, what to run next
pdfsift toc file.pdf              # sections with page ranges, e.g. "- 3 Methods (pp. 4-7)"
pdfsift file.pdf --pages 4-7      # only those pages (PDF page order, from 1)
pdfsift file.pdf                  # Markdown on stdout
pdfsift file.pdf -o file.md       # to a file
pdfsift file.pdf --pages 10-12    # a slice ("3", "2-4", "1,5-7"), to fit a context window
pdfsift file.pdf --no-page-markers
pdfsift file.pdf --assets figs/   # where images go
pdfsift file.pdf --no-images      # text only, images as [image: caption]
pdfsift file.pdf --json           # the same content as JSON items, each with its page (schema: docs/schema/pdfsift.schema.json)
pdfsift mcp                       # MCP server on stdio (pdf_info, pdf_toc, pdf_to_markdown)
```

- **Images** are written as files and referenced as `![caption](path)`: on stdout they go to `<tmp>/pdfsift/<name>-<hash>/` with absolute paths (the header comment names the directory), with `-o out.md` to `out_assets/` with relative paths. Open the path to look at an image.
- `<!-- page: N -->` marks where each page starts, so an agent can cite pages. A header comment names the source file and the pages converted.
- Warnings (for example, a page without a text layer) go to stderr; `-q` silences them.
- Exit codes: 0 success (maybe with warnings), 1 missing file / not a PDF / damaged, 2 invalid arguments, 3 needs a password (use `--password`), 4 no text in the selection (scans only: the Markdown and page images are still written; run OCR). Errors say what to do next.
- Output is deterministic: the same PDF always gives the same Markdown.
- Full reference (every Markdown construct, JSON items, warnings, exit codes, MCP setup): [docs/usage.md](docs/usage.md).

### For agents

- **MCP:** `claude mcp add pdfsift -- npx -y @vitorsilverio/pdfsift mcp` (Claude Code), or `{"command": "npx", "args": ["-y", "@vitorsilverio/pdfsift", "mcp"]}` in other clients ([more](docs/usage.md#client-configuration)). Tools: `pdf_info`, `pdf_toc`, `pdf_to_markdown {path, pages?, images?, password?}`.
- **Listed in** the [official MCP Registry](https://registry.modelcontextprotocol.io/v0.1/servers?search=io.github.vitorsilverio/pdfsift) (`io.github.vitorsilverio/pdfsift`) and on [Glama](https://glama.ai/mcp/servers/vitorsilverio/pdfsift), where you can browse the tools, see the quality score and try the server online in the MCP Inspector:

  [![vitorsilverio/pdfsift MCP server](https://glama.ai/mcp/servers/vitorsilverio/pdfsift/badges/score.svg)](https://glama.ai/mcp/servers/vitorsilverio/pdfsift)
- **Agent Skill and AGENTS.md snippet:** [`integrations/`](integrations/).
- `pdfsift --help` is short and written so an agent can use the tool from it alone.

## What it does

- **Reading order**: columns are read one after the other; a paragraph that continues in the next column or page is joined back.
- **Hyphenation**: words split at line ends are rejoined (`interopera-` / `bility` → `interoperability`), while real hyphens stay.
- **Page furniture**: running headers, footers and page numbers are dropped.
- **Headings**: from the PDF outline, the structure tags, or the typography (size and weight), with the right level.
- **Lists**: bullets, numbers and letters, nested, continuing across page breaks; a list item's second paragraph stays in the item.
- **Inline**: `**bold**`, `*italic*`, `` `code` `` on the exact span, and `[text](url)` from the PDF's link annotations (a URL broken across lines comes out whole). Emphasis that covers a whole heading or paragraph is dropped as noise.
- **Footnotes**: `[^1]` at the call and `[^1]: text` at the end of the same page; endnotes keep their place.
- **Block quotes**: `>` with nesting, from indentation or tags.
- **Images**: JPEGs are copied unchanged, other images become PNG (with transparency when there is any); each distinct image is written once; ornaments, rules and repeated decorations are dropped; the figure caption becomes the alt text instead of a separate paragraph.
- **Figures**: a chart or diagram drawn with vector graphics (or made of several images and labels) is rendered as one PNG, so its scattered labels do not end up as stray paragraphs.
- **Encrypted PDFs** (RC4, AES-128, AES-256) open without a password when the user password is empty, which is the common case; otherwise pass `--password`. A file whose permissions forbid copying text is still converted, with a warning.
- **Rotated pages**: `/Rotate`, offset page boxes and pages drawn sideways are read upright; text outside the CropBox is dropped, and turned text in the margins (the arXiv side stamp) is treated as page furniture.
- **Scanned pages**: a page that is only a picture of text is detected and saved as an image (the original JPEG when possible), with a warning to run OCR; a page with an invisible OCR layer keeps its text, marked as coming from OCR.
- **Tables**: a table whose grid is certain becomes a GFM pipe table, with column alignment; merged cells are flattened (the value repeated in every covered cell, multi-level headers joined with ` / `) when tags or the header geometry make the grid certain; otherwise a fenced code block with the text laid out by position, so nothing is invented. Captions come right before their table. On the test corpus (five producers): every cell right in the simple tables, including those split across a page break (joined, header once), and no prose mistaken for a table.

## Compared with `pdftotext`

The two-column test document above (15 paragraphs), typeset from the same source by Chrome, LibreOffice, LaTeX and Typst; `pdftotext` is Xpdf 4.00. "Whole paragraphs" counts source paragraphs that come out as one intact paragraph; "split words" counts line-end hyphens left in the text.

| Producer | `pdftotext` | `pdftotext -layout` | `pdfsift` |
|---|---|---|---|
| Chrome | 9/15 whole, 2 split words | 0/15, 2 | **15/15, 0** |
| LibreOffice | 6/15, 3 | 0/15, 56 | **15/15, 0** |
| LaTeX | 0/15, 29 | 0/15, 35 | **13/15, 0** |
| Typst | 0/15, 1 (+ soft hyphens left as spaces) | 0/15, 23 | **15/15, 0** |

Beyond the counts:
- On LaTeX, plain `pdftotext` interleaves the two columns line by line; `-layout` puts them side by side on the same line. pdfsift reads column 1, then column 2.
- `pdftotext` keeps Chrome's header and footer (date, title, `file:///…`, `1/3`) on every page; pdfsift removes them.
- `pdftotext` has no headings (they are plain lines) and drops Chrome's list markers, gluing items together. pdfsift emits `#`/`##`/`###` at the right level and nested lists.
- Size is similar: on a 6-page arXiv paper, 40.2k characters for pdfsift and 40.8k for `pdftotext` (53.1k with `-layout`). Markdown syntax costs about what removing the furniture saves.
- Tables: `pdftotext` flattens them into lines; `-layout` keeps the alignment but, in two of the test tables (LibreOffice, and a Word-made arXiv paper), shifts values into the wrong row. pdfsift gets both right as GFM tables.

On 14 structure-dependent questions over 18 PDFs (44 question × PDF pairs; [evals/](evals/)), the expected answer appears intact and in order in **100%** of pdfsift outputs (44/44), against 22% for `pdftotext` and 43% for `pdftotext -layout`, at about the same size as plain `pdftotext` (+4%) and 23% smaller than `-layout`. The questions were written by the authors on a corpus the heuristics were tuned on, so read this as an upper bound.

**On real third-party PDFs** (8 documents, 165 pages, none used to tune the heuristics before they were added: IRS forms and instructions, a 62-page Census report, Word articles in Portuguese, a Google Docs article, Google Slides and PowerPoint decks; [evals/third_party.py](evals/third_party.py)):

| | pdfsift | `pdftotext` | `pdftotext -layout` |
|---|---:|---:|---:|
| Whole paragraphs | **33/36** | 21/36 | 19/36 |
| Headings found | **52/55** (4 false) | 42/55 | 35/55 |
| Table rows with every cell in the right row | **18/22** | 8/22 | 15/22 |
| Running headers/footers left | **74** | 139 | 139 |
| Size (characters) | 845k | **516k** | 762k |

pdfsift is larger overall because of one document: the Census report's dot leaders and wide tables make it 2.2× `pdftotext`. Without it, pdfsift's output is 2% smaller than `pdftotext`'s. Known failures are listed in [finding 041](docs/achados/041-corpus-terceiros.md).

**Speed:** about 30 ms per page (release build, the whole corpus), about 3× `pdftotext`, which does no layout analysis ([finding 045](docs/achados/045-velocidade.md), [evals/bench.py](evals/bench.py)). The same PDF gives byte-identical output on Linux, macOS and Windows, checked in CI.

Methodology and per-document results (in Portuguese): [text](docs/achados/011-primeira-saida-markdown.md), [tables](docs/achados/013-tabelas-minimas.md), [evaluation](docs/achados/021-avaliacao-agentes.md), [third-party corpus](docs/achados/041-corpus-terceiros.md).

## Limitations

- **Tables** with merged cells in the body come out as a laid-out code block when the PDF has no tags (LaTeX, untagged LibreOffice).
- No OCR: scanned pages are saved as images and reported on stderr.
- A vector figure without any text label is not rendered; a rendered figure's rectangle can include nearby body text.
- Dot leaders (`. . . .`) in tables of contents and wide tables are kept, which inflates some reports.
- The output contract, frozen since 1.0.0, is in [docs/usage.md](docs/usage.md) (output contract, warnings, exit codes, MCP setup); the JSON is described by [docs/schema/pdfsift.schema.json](docs/schema/pdfsift.schema.json).

## Safety

- No network access, ever. pdfsift reads the input PDF and writes only to stdout or the `-o` path.
- Parsing is done by PDFium, the engine Chrome uses on untrusted web content; pdfsift's own code is written to skip or reject malformed data rather than crash and is fuzzed with mutated and hand-made hostile PDFs (cyclic outlines, self-drawing forms, absurd page boxes). A PDF that stalls the PDF engine is stopped after 60 s without progress on a page, with an error (`PDFSIFT_STALL_SECS` changes the limit, 0 turns it off).
- Release binaries come with SHA-256 checksums and GitHub build attestations (`gh attestation verify <file> --repo vitorsilverio/pdfsift`).

## Development

```sh
scripts/fetch-pdfium.sh            # downloads PDFium into .pdfium/ (needs gh)
cargo run -- file.pdf              # convert
cargo run -- dump file.pdf         # inspect what the PDF engine sees
cargo run -- blocks file.pdf       # inspect the layout blocks
scripts/gen-corpus.sh              # regenerate test PDFs (pandoc, lualatex, typst, LibreOffice, Chrome)
```

The full usage and output reference is [docs/usage.md](docs/usage.md). PDFium is loaded at run time from `PDFSIFT_PDFIUM`, next to the executable (or in `pdfium/` beside it), from `.pdfium/<platform>/` (debug builds only), or from the system library path (not on Windows). The design docs are in [`docs/`](docs/) (Portuguese): [vision](docs/visao.md), [architecture](docs/arquitetura.md), [distribution](docs/distribuicao.md), [roadmap](docs/roadmap.md), [decisions](docs/decisoes/).

## License

Licensed under either of [Apache License 2.0](LICENSE-APACHE) or [MIT license](LICENSE-MIT), at your option. The binaries also contain PDFium and its dependencies under their own permissive licenses; see [THIRD_PARTY_LICENSES](THIRD_PARTY_LICENSES).

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

TDQS

A4.1/5.0

Scored across 3 tools

Disambiguation5/5

Each tool targets a distinct layer of the reading workflow: pdf_info for metadata/diagnosis, pdf_toc for navigation, pdf_to_markdown for extraction. Descriptions explicitly sequence them (info first, toc for long PDFs, then markdown with pages), so an agent can pick without confusion.

Naming Consistency4/5

All three share a clear `pdf_` prefix in snake_case, which is predictable and readable. The minor inconsistency is that `pdf_to_markdown` names an output format/action while `pdf_info` and `pdf_toc` name resources, but the grouping is still obvious.

Tool Count4/5

Three tools is lean but each earns its place in a coherent pipeline (diagnose → navigate → extract). It sits at the thin end for a document-processing server, where a search or page-render tool would plausibly add value.

Completeness3/5

The core read path is covered end to end, but notable gaps remain for the stated domain: no OCR or fallback for scanned pages, no search/grep within a PDF, and no tool to render or fetch a specific page as an image (figures are only linked by path). These are acknowledged limitations that will cause dead ends on scanned or very long documents.

Maintenance

ActivityMaintained
ResponsivenessNo recent community issues