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.
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)
What's in the box
- Rendering modes & image handling — section-first or page-first HTML/Markdown, an optional
table of contents, and
embed/external(animg/folder) /dropimage modes. Rendering » - Raw extraction —
extract_tables(),extract_images(),extract_links(),extract_fonts()give you the structured pieces, not rendered output. Extraction » - The
.dpdfdocument model —distill()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 semanticsearch()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 withdistillpdfinstalled can driveinfo / toc / read / find / searchagainst 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file distillpdf-0.0.34-cp38-abi3-win_amd64.whl.
File metadata
- Download URL: distillpdf-0.0.34-cp38-abi3-win_amd64.whl
- Upload date:
- Size: 9.1 MB
- Tags: CPython 3.8+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
872c10700cd41de6481272e74de982a36ead243ab0c383e2550ffe4629e55469
|
|
| MD5 |
a5179aff1a6820ae04b3ed380ac44680
|
|
| BLAKE2b-256 |
501be1e747dfd3b9ac236fa4620d5154994cb3eaa47b608aa20835d462caaf9a
|
Provenance
The following attestation bundles were made for distillpdf-0.0.34-cp38-abi3-win_amd64.whl:
Publisher:
publish.yml on kkollsga/distillpdf
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
distillpdf-0.0.34-cp38-abi3-win_amd64.whl -
Subject digest:
872c10700cd41de6481272e74de982a36ead243ab0c383e2550ffe4629e55469 - Sigstore transparency entry: 1781282804
- Sigstore integration time:
-
Permalink:
kkollsga/distillpdf@b07f48773b0295091db4b607f0bda1697a8cfb91 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/kkollsga
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b07f48773b0295091db4b607f0bda1697a8cfb91 -
Trigger Event:
push
-
Statement type:
File details
Details for the file distillpdf-0.0.34-cp38-abi3-manylinux_2_39_x86_64.whl.
File metadata
- Download URL: distillpdf-0.0.34-cp38-abi3-manylinux_2_39_x86_64.whl
- Upload date:
- Size: 8.4 MB
- Tags: CPython 3.8+, manylinux: glibc 2.39+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
59249bf44db01599c8ae250e10c565ff6be2807f8dc5dfd612550172c0ad5fe0
|
|
| MD5 |
a51c7018ebbf38b208ad5d90e2e4e2c5
|
|
| BLAKE2b-256 |
b0efcd38e582227e0cf60026f60a5df8c5452ae04158f5baa9adffc5dfd85a6d
|
Provenance
The following attestation bundles were made for distillpdf-0.0.34-cp38-abi3-manylinux_2_39_x86_64.whl:
Publisher:
publish.yml on kkollsga/distillpdf
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
distillpdf-0.0.34-cp38-abi3-manylinux_2_39_x86_64.whl -
Subject digest:
59249bf44db01599c8ae250e10c565ff6be2807f8dc5dfd612550172c0ad5fe0 - Sigstore transparency entry: 1781282110
- Sigstore integration time:
-
Permalink:
kkollsga/distillpdf@b07f48773b0295091db4b607f0bda1697a8cfb91 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/kkollsga
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b07f48773b0295091db4b607f0bda1697a8cfb91 -
Trigger Event:
push
-
Statement type:
File details
Details for the file distillpdf-0.0.34-cp38-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: distillpdf-0.0.34-cp38-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 8.0 MB
- Tags: CPython 3.8+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
71b42567d2d163c86cdbd3e1a91b85ef6601e5088d49e97b489755c519ea9de5
|
|
| MD5 |
472be6093cdbce2fd8eb14ccf1e3d585
|
|
| BLAKE2b-256 |
661b222a52b8f4d8959ac7a565776b38a037e708cbadfe25bedd3e56c2fab025
|
Provenance
The following attestation bundles were made for distillpdf-0.0.34-cp38-abi3-macosx_11_0_arm64.whl:
Publisher:
publish.yml on kkollsga/distillpdf
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
distillpdf-0.0.34-cp38-abi3-macosx_11_0_arm64.whl -
Subject digest:
71b42567d2d163c86cdbd3e1a91b85ef6601e5088d49e97b489755c519ea9de5 - Sigstore transparency entry: 1781282395
- Sigstore integration time:
-
Permalink:
kkollsga/distillpdf@b07f48773b0295091db4b607f0bda1697a8cfb91 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/kkollsga
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b07f48773b0295091db4b607f0bda1697a8cfb91 -
Trigger Event:
push
-
Statement type: