Skip to content
jedardenPublic

About

A high-quality PDF text extraction library — improving on reading order, font encoding recovery, structured output, and hybrid vector/OCR pipelines

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2,933 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

pdftract

crates.io PyPI docs.rs License MSRV

pdftract is a pure-Rust PDF text extraction library built for the cases where other tools give up: scanned documents, unusual font encodings, multi-column layouts, footnotes, mixed-mode pages, and encrypted files. Where most extractors treat PDF text extraction as a coordinate sort, pdftract runs a full reading-order pipeline — segmenting layout regions, recovering broken font encodings, routing each page to the right extraction mode (vector, OCR, or hybrid), and emitting structured JSON with per-span provenance. If your PDFs are academic papers, legal filings, financial reports, or anything else that wasn't typeset in a word processor, pdftract is what you want.

⚠️ Development status (evidence-audited 2026-09-26). pdftract is pre-release and mid-stabilization (tracked in bead pdftract-f19fd721). The tables below describe the designed capability set; what is actually verified today:

  • The canonical smoke extraction passes at HEAD — the W3C WAI dummy PDF at tests/fixtures/test-minimal.pdf extracts the text Dummy PDF file. The broader fixture corpus remains pre-release work and is not represented as a shipped compatibility guarantee.
  • The scanned/mixed OCR acceptance gate passes at HEAD — scripts/measure-wer.sh verifies five clean 300-DPI fixtures below WER 3% (aggregate WER 0.64% in the recorded gate run, commit 7a04f714). This verifies the OCR corpus gate, not the still-stabilizing general extraction pipeline.
  • pdftract serve works at HEAD — GET /health → 200 and POST /extract → 200 over the real binary (axum ConnectInfo wiring fixed in commit 2566480f on 2026-09-20, re-verified 2026-09-26; regression-tested by crates/pdftract-cli/tests/serve-e2e.rs). The earlier "every request returns HTTP 500" status (re-confirmed 2026-09-15) predated that fix.
  • CI is not wired to git events yet — nothing runs automatically on push/PR (bead pdftract-a8d7bd1d, open), and no completed end-to-end CI run has been retained — the stabilization baseline records "no retained end-to-end CI proof."
  • Nightly Argo evidence is split between local and cluster evidence — the 2026-09-15 fuzz numbers in ADR-003 are local coverage evidence only. The pdftract-nightly-supply-chain CronWorkflow is now present in the in-tree and iad-ci GitOps manifests, and iad-ci created verification Workflow pdftract-nightly-supply-chain-1790623980; its setup pod completed successfully and its retained pod/log evidence was observed. The terminal phase, exit status, and subsequent task logs still require a healthy API read after the namespace quota and unrelated Argo sync failures clear. The existing pdftract-nightly-fuzz check reported 11 failed and 0 successful runs, so neither result should be described as a passing nightly cycle yet.
  • No supported release is published — pdftract-core is on neither crates.io nor docs.rs; no wheels or images exist. GitHub exposes only the test-only v0.1.0-test release entry used for release-cascade testing, not a consumable v0.1.0 release.

Grep results with page, bounding box, and confidence

pdftract grep --json --no-progress -E 'Lorem (ipsum|dolor)' tests/fixtures/grep-corpus/corpus/synthetic_1.pdf

How it compares

Capability pdftract pdfplumber pypdf pdfminer
Multi-column reading order 🚧 Full layout segmentation¹ ⚠ Heuristic ❌ ⚠ Partial
Footnotes & sidebars 🚧¹ ❌ ❌ ❌
Font encoding recovery 🚧 Glyph name → fingerprint → shape¹ ⚠ ToUnicode only ⚠ ToUnicode only ⚠ ToUnicode only
Scanned / mixed PDF (OCR) ✅ Per-page hybrid routing² ❌ ❌ ❌
PDF/UA structure tree 🚧³ ❌ ⚠ Partial ❌
PDF decryption (RC4/AES) 🚧 (decrypt feature)⁴ ⚠ Partial ⚠ Partial ⚠ Partial
Per-span bounding boxes + confidence 🚧¹ ✅ ❌ ⚠ Partial
Streaming extraction (large files) 🚧⁵ ❌ ❌ ❌
CJK scripts ❌⁶ (cjk feature) ⚠ ⚠ ⚠
HTTP microservice mode ✅⁷ (serve) ❌ ❌ ❌
Language Rust + Python + C ABI Python Python Python

✅ = backed by committed test/fixture evidence · 🚧 = implemented in the source tree, not yet verified end-to-end · ❌ = not working at HEAD · third-party columns unchanged

¹ Implemented, but unverifiable until the page-tree parse regression is fixed (see development status above): pdftract extract currently fails on all fixtures, including these paths. ² Page classification/routing and the scanned/mixed acceptance corpus are verified: the five clean 300-DPI fixtures measure WER <3% in scripts/measure-wer.sh, with the gate run by the pdftract-ci Argo WorkflowTemplate (commit 7a04f714). ³ Structure-tree parser implemented and tagged-PDF corpus ready (bead bf-5pyzm); end-to-end verification pending the parse fix. ⁴ RC4/AES-128/AES-256 implemented with unit-test coverage (bead pdftract-4mdfv: 217/217 parser tests at close, 2026-06-03); the end-to-end encrypted-file path is blocked by the parse regression. ⁵ Lazy per-page decode implemented (bead bf-2y2rp); bounded-memory behavior on real documents is unverifiable until the parse fix. ⁶ Feature flag, corpus, and acceptance tests all exist; the acceptance tests fail in the most recent recorded run (0/5, notes/bf-1wczm-cjk_encoding-run.log). ⁷ Verified end-to-end at HEAD over the real binary: GET /health → 200, POST /extract → 200 (ConnectInfo wiring fixed in 2566480f; regression-tested by crates/pdftract-cli/tests/serve-e2e.rs).

The matrix and marked release claims are checked against their implementation, test, fixture, and bead evidence by scripts/audit_readme_capabilities.py. Run make readme-audit after changing a capability marker or release status.

Platform Support

Platform Status
Linux x86_64 Primary development platform — the test suite runs here during development; automated PR CI not yet wired (see development status above)
Linux aarch64 Cross-compile build target in the CI pipeline; tests are not executed on-device; CI trigger wiring pending
macOS x86_64 Cross-compile target defined in CI; no completed CI build recorded yet; manual smoke procedure documented for first release
macOS aarch64 Cross-compile target defined in CI; no completed CI build recorded yet; manual smoke procedure documented for first release
Windows x86_64 Cross-compile target defined in CI; no completed CI build recorded yet; manual smoke procedure documented for first release

See docs/operations/manual-platform-smoke.md for the per-release smoke procedure (no release has shipped yet).

Installation

Available channel: build from this repository. No package registry, release archive, container image, Homebrew formula, or hosted documentation site is published yet. Do not use the planned commands below as installation instructions.

Minimum Supported Rust Version (MSRV): 1.78

Build from source

The workspace does not publish a root package, so target the CLI crate:

git clone https://github.com/jedarden/pdftract.git
cd pdftract
cargo build --locked --release -p pdftract-cli --bin pdftract
cargo install --locked --path crates/pdftract-cli

The canonical source smoke fixture is tests/fixtures/test-minimal.pdf; it is the W3C WAI dummy PDF and should produce Dummy PDF file when extracted.

Planned release channels — not published

The following channels are design targets only. They are intentionally not usable until a real release has been published and independently verified.

Channel Intended location Current status
Rust library and CLI crates.io Not published; source build only
Python bindings PyPI Not published
Container images GHCR (ghcr.io/jedarden/pdftract) Not published
Pre-built binaries GitHub Releases Only test-only v0.1.0-test; no supported release
Homebrew jedarden/homebrew-tap Pending: the tap is reachable, but Formula/pdftract.rb is not published; see the verification record below before treating Homebrew as available
Hosted user guide pdftract.com Domain is not a supported channel

Homebrew verification record (2026-10-17). The v1.2.0 release was re-published on 2026-09-29 and now carries a SHA256SUMS asset, but the handoff is still not renderable: the aggregate (231 bytes) lists only the two binary archives — the required source/pdftract-v1.2.0.tar.gz line is absent, and SHA256SUMS.sig and SHA256SUMS.pem remain unpublished (HTTP 404), so the formula's signed source-archive checksum input (see docs/notes/homebrew-tap-strategy.md §5) still does not exist. The source archive itself is unchanged and still declares workspace version 0.1.0 under the v1.2.0 tag (archive sha256 db8390ced458a1e3d3816e43a3488a3e643bcb43a8ac7404f1de38b28f503e75), so a formula rendered as 1.2.0 would still fail its own pdftract --version test block. The tap is unchanged: the Forgejo origin main remains at c7aec641d5cf9e638285fdbc706499f19495f6a2 with only Formula/.gitkeep (verified by authenticated clone), and the client-facing GitHub mirror still returns 404 for Formula/pdftract.rb (last push 2026-09-15). The release pipeline that would produce the complete signed handoff is enabled (declarative-config 2026-10-07) but currently failing before release: two pdftract-main-release attempts on 2026-10-17 (08:17Z, 08:30Z) both failed in their pdftract-main-verify child at the setup step (git clone exit 128, same failure twice — systematic, suspected stale in-cluster Forgejo credential; owned by the release cascade, not this channel). The approved verification command — brew tap jedarden/tap https://github.com/jedarden/homebrew-tap.git && brew install jedarden/tap/pdftract && pdftract --version — remains unrun on this host (command -v brew exited 1; the cascade leg performs it in a pinned homebrew/brew:<semver> container). Homebrew remains pending a correctly versioned signed release handoff and Formula/pdftract.rb, followed by that smoke test.

The locally supported Docker variants are default and full; their build and smoke-test contract is automated by scripts/verify-docker.sh. The release workflow must publish and verify an immutable versioned reference before any pull command is added here. OCR, remote sources, profiles, and PDFium remain planned feature tiers until their clean-checkout builds are repaired.

Quickstart

Rust

use pdftract_core::{extract_pdf, ExtractionOptions};
use std::path::Path;

let opts = ExtractionOptions::default();
let doc = extract_pdf(Path::new("report.pdf"), &opts)?;

for page in &doc.pages {
    println!("Page {}: {} spans", page.page_number, page.spans.len());
}

Streaming extraction for large files (callback-based; return false to stop early):

use pdftract_core::extract_pdf_streaming;

extract_pdf_streaming(Path::new("large.pdf"), &opts, |page| {
    process(page);
    true // keep going
})?;

NDJSON output (one JSON object per page on stdout):

pdftract_core::extract_pdf_ndjson(Path::new("report.pdf"), &opts, std::io::stdout())?;

Python

import pdftract

doc = pdftract.extract("report.pdf")
print(f"{doc['metadata']['page_count']} pages")

for page in doc["pages"]:
    for span in page["spans"]:
        print(span["text"], span["bbox"], span["confidence"])

CLI

# Extract to JSON
pdftract extract report.pdf --json output.json

# Plain text to stdout
pdftract extract report.pdf --text -

# Markdown output
pdftract extract report.pdf --markdown -

# Run as an HTTP microservice (POST /extract, GET /health)
pdftract serve --bind 127.0.0.1:8080

# Compare two PDFs structurally
pdftract compare original.pdf revised.pdf

# Interactive page inspector
pdftract inspect report.pdf --page 3

# Diagnose extraction problems on a file
pdftract doctor report.pdf

# Validate PDF/UA or PDF/A conformance
pdftract validate report.pdf

# Stable content hash (for dedup / cache keys)
pdftract hash report.pdf

# Search for a pattern across pages
pdftract grep "invoice number" report.pdf

# Print page count and dimensions
pdftract pages report.pdf

# Classify each page (vector / scanned / mixed)
pdftract classify report.pdf

# Manage the local extraction cache
pdftract cache --list
pdftract cache --clear

# Migrate the local cache schema
pdftract migrate

# Verify a previously issued extraction receipt
pdftract verify-receipt receipt.json

# Generate client bindings from the C ABI headers
pdftract codegen --lang python

# Start the MCP (Model Context Protocol) server
pdftract mcp

Features

Browser / WASM

The pdftract-wasm workspace member supports in-browser vector-text extraction from an in-memory Uint8Array. Its supported core feature set is exactly serde, decrypt, and quick-xml; the filesystem cache is disabled so the zstd-sys native C dependency is not included.

Build the binding for the browser target with:

rustup target add wasm32-unknown-unknown
cargo check -p pdftract-wasm --locked --target wasm32-unknown-unknown

The browser binding does not support scanned-page OCR, PDFium/full-page rendering, remote HTTP sources, the filesystem cache, profiles, optional CJK or receipt tiers, or the pdftract serve HTTP process. Those features remain native-only. A scanned page is therefore outside the WASM contract rather than silently falling back to OCR.

The default extraction pipeline compiles from source; extraction correctness is mid-stabilization — see the development-status note above for what is currently verified. Optional features unlock heavier dependencies when their feature gates are buildable:

Feature What it adds Enable with
ocr Tesseract/Leptonica OCR for scanned and mixed pages Planned; not buildable in the current clean checkout
decrypt RC4, AES-128, AES-256 PDF decryption cargo add pdftract-core --features decrypt
cjk CJK script support (Chinese, Japanese, Korean) cargo add pdftract-core --features cjk
full-render Full-page rasterization for assisted OCR and inspect UI cargo add pdftract-core --features full-render

Python wheels and additional Docker feature tiers are planned; no wheels or published images exist yet.

What it does

Correct reading order. Most PDF extractors sort glyphs by Y then X coordinate. That breaks on multi-column articles, legal documents with sidebars, academic papers with footnotes, and anything typeset in a non-linear flow. pdftract segments each page into layout regions first, orders the regions, then emits text within each region — so the output reads the way a human would.

Font encoding recovery. PDFs can legally omit ToUnicode CMaps and describe only glyph IDs. When that happens, other extractors emit garbage or question marks. pdftract works through a layered recovery pipeline: glyph name lookup (standard and Adobe glyph lists), font fingerprinting against a known-font database, and finally glyph outline shape matching. Most documents that trip up other tools extract cleanly.

Per-page hybrid routing. Each page is independently classified as vector text, fully scanned (image-only), or mixed. Vector pages go through the fast extraction path. Scanned pages go to full OCR. Mixed pages use assisted OCR — vector spans anchor the OCR so it doesn't drift. This means one call handles an entire document regardless of how it was produced.

Structure tree extraction. PDF/UA and PDF/A files carry a logical structure tree (headings, paragraphs, tables, lists) separate from the visual rendering. pdftract reads this directly when present, so accessible PDFs yield structured output without heuristics.

Structured output with provenance. The primary output format is JSON. Every text span carries its bounding box, font name, point size, and a confidence score. This makes pdftract suitable as a preprocessing step for LLM pipelines, document indexing, and data extraction workflows that need to trace output back to the source page.

Streaming extraction. For large files, extract_pdf_streaming yields one page at a time so memory usage stays bounded regardless of document length.

Available SDKs

pdftract ships multiple integration surfaces from a single Rust core:

SDK Package Notes
Rust library pdftract-core on crates.io (planned) Primary API — 🚧 not published
CLI binary pdftract on crates.io (planned) Wraps the library — 🚧 not published
Python bindings pdftract on PyPI (planned) PyO3-based wheels — 🚧 not published
C shared library libpdftract Stable C ABI; use pdftract codegen to generate FFI headers for your language — 🚧 coming soon
Docker image ghcr.io/jedarden/pdftract (planned) Local default/full builds only; 🚧 not published
HTTP microservice pdftract serve REST API for language-agnostic integration (build from source)

Additional language SDK packages (Go, Node.js, Ruby) are in progress, built on top of the C ABI.

Documentation

License

Licensed under either of:

at your option.


Part of jedarden.com

This GitHub repo is a read-only mirror of git.ardenone.com/jedarden/pdftract — issues and PRs are welcome here either way.

About

A high-quality PDF text extraction library — improving on reading order, font encoding recovery, structured output, and hybrid vector/OCR pipelines

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages