pdfsift
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); 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,--jsonand an MCP server make it easy for agents to read only what they need (see Limitations and the changelog).
$ 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 library (the PDF engine of Chrome) next to the executable; nothing is downloaded at run time.
Channel | Command |
npm (no install) |
|
npm (global) |
|
PyPI (no install) |
|
PyPI (global) |
|
Homebrew |
|
Shell (Linux, macOS) |
|
PowerShell (Windows) |
|
Archives |
|
Cargo |
|
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 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.
Related MCP server: pdf-inspector-mcp
Usage
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
: on stdout they go to<tmp>/pdfsift/<name>-<hash>/with absolute paths (the header comment names the directory), with-o out.mdtoout_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;
-qsilences 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.
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). Tools:pdf_info,pdf_toc,pdf_to_markdown {path, pages?, images?, password?}.Listed in the official MCP Registry (
io.github.vitorsilverio/pdfsift) and on Glama, where you can browse the tools, see the quality score and try the server online in the MCP Inspector:Agent Skill and AGENTS.md snippet:
integrations/.pdfsift --helpis 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]: textat 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 |
|
|
|
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
pdftotextinterleaves the two columns line by line;-layoutputs them side by side on the same line. pdfsift reads column 1, then column 2.pdftotextkeeps Chrome's header and footer (date, title,file:///…,1/3) on every page; pdfsift removes them.pdftotexthas 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:
pdftotextflattens them into lines;-layoutkeeps 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/), 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):
pdfsift |
|
| |
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.
Speed: about 30 ms per page (release build, the whole corpus), about 3× pdftotext, which does no layout analysis (finding 045, 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, tables, evaluation, third-party corpus.
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 (output contract, warnings, exit codes, MCP setup); the JSON is described by docs/schema/pdfsift.schema.json.
Safety
No network access, ever. pdfsift reads the input PDF and writes only to stdout or the
-opath.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_SECSchanges 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
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. 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/ (Portuguese): vision, architecture, distribution, roadmap, decisions.
License
Licensed under either of Apache License 2.0 or MIT license, at your option. The binaries also contain PDFium and its dependencies under their own permissive licenses; see 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.
Available Tools
3 toolspdf_infoPDF infoARead-only
Metadata and diagnosis of a PDF: page count, title, author, whether pages have a text layer (scanned pages need OCR), whether it is tagged or encrypted. Cheap: call it first on a PDF you have not seen, to decide how much to read.
Inputs: path (required), password.
pdf_tocPDF table of contentsARead-only
Table of contents of a PDF with the page where each section starts (from the PDF outline, else from detected headings). Use it on long PDFs (more than ~20 pages) to find the pages you need, then call pdf_to_markdown with "pages".
Inputs: path (required), password.
pdf_to_markdownPDF to MarkdownAIdempotent
Convert a PDF, or some of its pages, into structured Markdown: headings, paragraphs, lists, tables and image links, with running headers and footers removed and columns in reading order. <!-- page: N --> comments mark where each page starts, so you can cite pages. Images are written to a temporary directory and linked by absolute path (open the file to see a figure); images=false skips them. Output longer than 200000 characters is cut: for long PDFs call pdf_toc first and read the relevant pages. Scanned pages have no text (no OCR); they come back as page images.
Inputs: path (required), pages, images, password.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 3 tools
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.
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.
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.
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
Related MCP Connectors
High-fidelity PDF to structured Markdown conversion and document field extraction.
PDF and image links to clean Markdown and text for AI: headings, columns, page markers, OCR.
PDF to Markdown and PDF to text from PDF URLs, page by page, with OCR for scanned pages
PDF to text and Markdown, tables kept, scanned pages read by AI OCR.
Related MCP Servers
- MIT
- AlicenseAqualityDmaintenanceEnables AI agents to process and inspect PDFs by detecting document type, extracting text, and generating Markdown with layout information.71MIT
- FlicenseNot gradedqualityCmaintenanceConverts PDFs to Markdown for AI optimization, with tools to detect PDF type (text-based, scanned, mixed, image-based) and support page ranges, raw/compact/page-break options.-
- FlicenseNot gradedqualityDmaintenanceConvert PDFs, Word documents, Excel/CSV files, and YouTube videos into clean, structured Markdown for AI agents, LLMs, and knowledge tools.1-