pdf-to-markdown
Convert PDF to Markdown with image preservation. Solves markitdown's image loss problem by combining markitdown + PyMuPDF.
Why?
markitdown (133k+ ⭐) is excellent for converting documents to Markdown, but it completely loses PDF images. This tool fixes that by intelligently merging markitdown's superior text extraction with PyMuPDF's lossless image extraction.
| Metric | markitdown only | PyMuPDF only | This tool |
|---|---|---|---|
| Text quality | 95% | 90% | 95% |
| Image preservation | ❌ 0% | ✅ 99% | ✅ 99% |
| Table support | ✅ 85% | ⚠️ 60% | ✅ 85% |
| Speed | ⚡ Fast | ⚡ Fast | ⚡ Fast |
Quick Start
# Install
pip install pymupdf "markitdown[all]"
# Convert (auto-detect strategy)
python -m pdf_to_markdown document.pdf
# Specify output directory
python -m pdf_to_markdown document.pdf -o output/
# Batch convert
python -m pdf_to_markdown *.pdf -o output/
# Extract images only
python -m pdf_to_markdown document.pdf --images-only
# Force strategy
python -m pdf_to_markdown document.pdf --strategy merge # markitdown + PyMuPDF
python -m pdf_to_markdown document.pdf --strategy pymupdf # pure PyMuPDF
How It Works
Input PDF
│
▼
┌─────────────────────────────────────┐
│ Step 1: Auto-detect PDF type │
│ - Page count, image count, scanned │
│ - Select best strategy │
└─────────────────────────────────────┘
│
├─ Text-only PDF ──→ pymupdf (fastest)
│
└─ Mixed content ──→ markitdown + PyMuPDF merge
│
▼
┌─────────────────────────────────────┐
│ Step 2: Parallel extraction │
│ - markitdown for text/structure │
│ - PyMuPDF for images (parallel) │
└─────────────────────────────────────┘
│
▼
┌─────────────────────────────────────┐
│ Step 3: Smart merge │
│ - Images inserted at correct pos │
│ - Footer/header pattern matching │
│ - Quality report generation │
└─────────────────────────────────────┘
│
▼
Output: document_with_images.md + images/
Strategies
| Strategy | Best For | How |
|---|---|---|
auto (default) |
Everything | Detects PDF type, picks best strategy |
merge |
Mixed content PDFs | markitdown text + PyMuPDF images |
pymupdf |
Text-only PDFs | Pure PyMuPDF extraction |
Quality Check
After conversion, validate the output:
python -m pdf_to_markdown.quality_check output.md
python -m pdf_to_markdown.quality_check output.md --verbose # detailed report
python -m pdf_to_markdown.quality_check output.md --json # machine-readable
Output:
📊 Basic Info:
File size: 1,234 KB
Total lines: 18,533
📝 Structure:
Headings: 320
Tables: 4,400 rows
🖼️ Images:
References: 645
Quality Score: 95/100 (✅ Excellent)
Benchmark
Tested on: 550-page Chinese technical manual with 645 images
| Tool | Time | Images | Text Accuracy | Overall |
|---|---|---|---|---|
| markitdown only | 15s | ❌ 0 | 95% | ⭐⭐⭐ |
| PyMuPDF only | 8s | ✅ 645 | 90% | ⭐⭐⭐⭐ |
| This tool | 20s | ✅ 645 | 95% | ⭐⭐⭐⭐⭐ |
| marker-pdf | 120s | ✅ 620 | 98% | ⭐⭐⭐⭐⭐ |
Installation
# Minimal (recommended)
pip install pymupdf "markitdown[all]"
# For scanned PDFs (OCR)
pip install marker-pdf
# From source
git clone https://github.com/Leomeie/pdf-to-markdown.git
cd pdf-to-markdown
pip install -e .
Tool Comparison
See docs/tool-comparison.md for detailed comparison of PDF-to-Markdown tools.
Related Projects
- markitdown - Microsoft's document converter (133k+ ⭐)
- PyMuPDF - Fast PDF library (5k+ ⭐)
- marker - High-quality PDF converter (20k+ ⭐)
License
MIT
Contributing
Contributions welcome! Please open an issue or PR.
Metadata
Release files for markitdown-pdf 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| markitdown_pdf-1.0.0.tar.gz | 11.7 kB | Without provenance | Details for markitdown_pdf-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| markitdown_pdf-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for markitdown_pdf-1.0.0-py3-none-any.whl |
Total release size: 24.5 kB
Release files / markitdown_pdf-1.0.0.tar.gz
| Download URL | markitdown_pdf-1.0.0.tar.gz |
|---|---|
| Size | 11.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0200f8166845509d066ae33d4c435ea93717a2f0318621289db7e092d955d9e0
|
|
BLAKE2b-256 checksum How to use checksums |
de879a143ebe992d0c85e230da590aeb0c6a28987406ea388ebe37b1c5693f04
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.11
|
Release files / markitdown_pdf-1.0.0-py3-none-any.whl
| Download URL | markitdown_pdf-1.0.0-py3-none-any.whl |
|---|---|
| Size | 12.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
df78c80d7e462b9c8bc2cff378a7fcbb9e95d9f5539d8be671583153f8b38cf4
|
|
BLAKE2b-256 checksum How to use checksums |
84fb529c578f2a8dc9dac14c1f2f0ae674229ad1de483f320fb5d52d9289099c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.11
|
Security for markitdown-pdf 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.