Skip to main content

Pure-Rust PDF extraction that distills documents into clean, LLM-ready HTML — for LLMs and RAG, built on lopdf

Project description

distillPDF

Turn any PDF into clean, LLM-ready HTML or Markdown — structure-aware, pure-Rust, MIT-licensed.

PyPI Python versions Docs License: MIT CI Built with Rust

distillpdf does structure-aware PDF extraction: it reconstructs a document's structure — reading order, headings, paragraphs, lists, tables, and figures — then emits compact, semantic HTML or Markdown (or plain text) ready to feed to an LLM or a RAG pipeline. No styling noise, no layout junk. It's pure Rust on lopdf, shipped to Python via PyO3 + maturin as a small, self-contained wheel — a lightweight, permissively licensed alternative to AGPL/heavyweight extractors (PyMuPDF, pdfminer, Unstructured), with no system dependencies and no Python runtime deps.

OCR for scanned PDFs: detect image-only pages and turn them into clean HTML or a compact searchable PDF, with a bundled offline engine or an optional accurate VLM — OCR guide » · example notebook »

Install

pip install distillpdf

Prebuilt wheels — no compiler or system libraries required. Installing also puts a distillpdf command on your PATH.

Quickstart

import distillpdf

doc = distillpdf.open("paper.pdf")        # or distillpdf.from_bytes(data)

doc.to_html()                             # writes paper.html (one self-contained file)
doc.to_markdown()                         # writes paper.md + an img/ folder of figures

html     = doc.to_html(return_string=True)   # ...or get the rendered string back instead
text     = doc.extract_text()                # plain text, in reading order
abstract = doc.section("abstract")           # one section's HTML (or None if no match)

By default these methods write a file and return 1; pass return_string=True for the string. PDF to HTML/Markdown — full guide »

distillpdf paper.pdf                  # HTML to stdout
distillpdf paper.pdf -o paper.html    # ...or to a file (.md infers Markdown)
distillpdf paper.pdf --markdown       # Markdown to stdout
distillpdf *.pdf -o out/              # batch: out/<name>.html per input
distillpdf scan.pdf --ocr             # OCR a scan → scan.searchable.pdf (bundled, no extra)

Command-line guide »

What's in the box

  • Rendering modes & image handling — section-first or page-first HTML/Markdown, an optional table of contents, and embed / external (an img/ folder) / drop image modes. Rendering »
  • Raw extractionextract_tables(), extract_images(), extract_links(), extract_fonts() give you the structured pieces, not rendered output. Extraction »
  • The .dpdf document modeldistill() once to a durable file, then re-render and query it forever with no source PDF and no re-analysis. .dpdf »
  • Honest search — coverage-reporting lexical find() (never a silent miss) and opt-in semantic search() over BAAI/bge-m3 vectors stored inside the .dpdf. Search »
  • OCR, two tiers — a bundled fast Tesseract engine (~0.8 s/page, offline, no download) and an optional accurate granite-docling VLM (structure + tables), folded into the same HTML / Markdown / searchable-PDF outputs. OCR » · setup »
  • An agent shell over .dpdf — any shell with distillpdf installed can drive info / toc / read / find / search against a distilled model, no SDK or server. CLI »

Comparison

distillPDF PyMuPDF pdfminer.six Unstructured
License MIT AGPL / commercial MIT Apache (heavy deps)
Structure-aware HTML partial
System deps none none none many
Implementation Rust C Python Python

Documentation

Full documentation — guides, the Python API reference, and the .dpdf format spec — lives at distillpdf.readthedocs.io. New here? Start with Getting started, then the Python API reference and the .dpdf format reference.

Early release — testers wanted

This is a young project and the API is small and may still change. If you have PDFs that come out wrong, please open an issue with the file (or a description) — real-world documents are exactly what this needs to get better. The .dpdf document model is also experimental (schema_version 0) and not yet a stable contract.

Contributing

Feedback is the fastest way to improve this. Try it on your PDFs and tell me where the output is wrong, star the repo if it's useful, and PRs are welcome. See Contributing and development to build from source or run the tests.

License

MIT — see LICENSE. Use it anywhere, including commercial and closed-source projects.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

distillpdf-0.1.0-cp38-abi3-win_amd64.whl (9.6 MB view details)

Uploaded CPython 3.8+Windows x86-64

distillpdf-0.1.0-cp38-abi3-manylinux_2_39_x86_64.whl (9.0 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.39+ x86-64

distillpdf-0.1.0-cp38-abi3-macosx_11_0_arm64.whl (8.5 MB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

File details

Details for the file distillpdf-0.1.0-cp38-abi3-win_amd64.whl.

File metadata

  • Download URL: distillpdf-0.1.0-cp38-abi3-win_amd64.whl
  • Upload date:
  • Size: 9.6 MB
  • Tags: CPython 3.8+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for distillpdf-0.1.0-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 dc899dd79a1c2a5f1507d1b70e8c46690500a1eaa5a6d1b12b486077e9069720
MD5 0401f9691486d957d4378009eb30369d
BLAKE2b-256 a046bb8227b60eb966abfc52040684977dc7189a90ce6e89a664a6c3c97d04cd

See more details on using hashes here.

Provenance

The following attestation bundles were made for distillpdf-0.1.0-cp38-abi3-win_amd64.whl:

Publisher: publish.yml on kkollsga/distillpdf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file distillpdf-0.1.0-cp38-abi3-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for distillpdf-0.1.0-cp38-abi3-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 f0aeb2c023a6281ce3744f084f2475a13a30534601ec49430d119df75cb79250
MD5 46096da5686ae83e23c02bf0a150ffad
BLAKE2b-256 a493e326c61d56e3bb476bb58f0f929daa8193a2a2a0d6f6badd9f3c92ce08cb

See more details on using hashes here.

Provenance

The following attestation bundles were made for distillpdf-0.1.0-cp38-abi3-manylinux_2_39_x86_64.whl:

Publisher: publish.yml on kkollsga/distillpdf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file distillpdf-0.1.0-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for distillpdf-0.1.0-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c6a88b7f3acf8593205af34c88cfbf093380634863a4a360b335c23d26c12a5c
MD5 c92d72d1242bddfb7a073a61166f8924
BLAKE2b-256 52d74cab79d172091da506bda7e683c51734933d519dc80df5816b95bdbdd2da

See more details on using hashes here.

Provenance

The following attestation bundles were made for distillpdf-0.1.0-cp38-abi3-macosx_11_0_arm64.whl:

Publisher: publish.yml on kkollsga/distillpdf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page