Supported Formats & Capabilities
| Input | Extensions | What It Handles |
|---|---|---|
.pdf |
Native text extraction (PyMuPDF) + automatic OCR on scanned or image-heavy pages (≥35% image area), multi-column reading order, repeated header/footer removal, password prompt (--password), optional image export (--assets). |
|
| Images | .png, .jpg, .jpeg, .webp, .bmp, .tif, .tiff |
Automatic EXIF orientation fix, multi-page TIFF support, layout/table reconstruction via PP-Structure or line-grouped plain OCR, automatic Tesseract fallback. |
| Excel | .xlsx, .xlsm |
Multi-region sheet splitting into separate Markdown tables, merged-cell expansion, 3-tier formula resolution (cached value → headless LibreOffice → pure-Python formulas), numeric alignment. |
Only the single .md file is written by default — no clutter folders. Pass --assets to export extracted images into <stem>_assets/ and --meta to emit a <stem>.meta.json sidecar.
Installation
Requires Python 3.10+. Install directly from GitHub in one command:
# Base install (native PDF + Excel)
pip install git+https://github.com/sinhsac/document-to-markdown.git
# Recommended: add PaddleOCR + PP-Structure layout/table analysis
pip install "document-to-markdown[ocr] @ git+https://github.com/sinhsac/document-to-markdown.git"
# Optional extras: Tesseract fallback or pure-Python Excel formula engine
pip install "document-to-markdown[tesseract] @ git+https://github.com/sinhsac/document-to-markdown.git"
pip install "document-to-markdown[excel-calc] @ git+https://github.com/sinhsac/document-to-markdown.git"
# Install all extras
pip install "document-to-markdown[all] @ git+https://github.com/sinhsac/document-to-markdown.git"
From Local Source (Editable Install)
git clone https://github.com/sinhsac/document-to-markdown.git
cd document-to-markdown
pip install -e ".[ocr]"
Standalone executables (Linux, Windows .exe, macOS — bundling native PDF, Excel, and Tesseract OCR) are also published on the Releases page. On the first OCR run, PaddleOCR downloads its detection/recognition/layout models once locally.
CLI Quick Start
Run via document-to-markdown or python -m document_converter.cli:
# Convert a PDF (outputs report.md only)
document-to-markdown report.pdf
# Convert a phone photo / scan (auto EXIF rotation + PP-Structure / PaddleOCR)
document-to-markdown scan.png
# Bilingual English + Vietnamese PDF formatted cleanly for AI/RAG ingestion
document-to-markdown report.pdf --mode ai --lang eng+vie
# Export extracted PDF images (_assets/) and metadata sidecar (.meta.json)
document-to-markdown report.pdf --assets --meta
# Batch convert an entire folder recursively
document-to-markdown data/input -o data/output --mode ai
# Convert an Excel workbook
document-to-markdown report.xlsx -o report.md
# Faster CPU OCR using lightweight mobile PP-OCRv5 models
document-to-markdown scan.pdf --ocr-profile mobile --ocr-version PP-OCRv5
# Disable PP-Structure layout analysis (faster plain OCR only)
document-to-markdown complex.pdf --no-structure
CLI Options Reference
| Option | Default / Values | Description |
|---|---|---|
inputs | path(s) | One or more files or directories to convert recursively. |
-o, --output | <input>.md | Output Markdown file path or destination directory. |
--mode | balanced | fidelity | ai | Output style (ai includes source comments and suppresses inline warning blockquotes). |
--ocr | auto | paddle | tesseract | off | OCR engine (auto prefers PaddleOCR/PP-Structure and falls back to Tesseract). |
--lang | vie (default) | OCR language (vie covers Vietnamese + English/Latin in PaddleOCR; supports eng+vie, etc.). |
--ocr-profile | auto | mobile | server | PaddleOCR model profile (mobile runs significantly faster on CPU). |
--ocr-version | unset | Model version such as PP-OCRv5, PP-OCRv4, PP-OCRv3. |
--det-model / --rec-model | unset | Explicit PaddleOCR detection/recognition model names (e.g. PP-OCRv5_mobile_det). |
--no-structure | flag | Skip PP-Structure layout/table parsing and use plain OCR. |
--assets, --images | flag | Export PDF images into <stem>_assets/. |
--meta | flag | Write machine-readable <stem>.meta.json sidecar. |
--preview | flag | Convert only the first 3 pages of a PDF. |
--password | flag | Prompt for password on encrypted PDFs. |
--no-recalculate | flag | Skip LibreOffice / pure-Python Excel formula recalculation. |
Python API
from document_converter import convert_file
output_md = convert_file(
"report.pdf",
"output/report.md",
mode="balanced", # "balanced" | "fidelity" | "ai"
ocr="auto", # "auto" | "paddle" | "tesseract" | "off"
ocr_lang="vie", # "vie", "eng", "eng+vie", ...
ocr_profile="auto", # "auto" | "mobile" | "server"
ocr_version=None, # e.g. "PP-OCRv5", "PP-OCRv4"
det_model=None, # e.g. "PP-OCRv5_mobile_det"
rec_model=None, # e.g. "latin_PP-OCRv5_mobile_rec"
export_images=False, # True to create output/report_assets/
export_meta=False, # True to create output/report.meta.json
)
How Processing Works & Known Limitations
- Hybrid PDF Routing: Native text pages are extracted directly via PyMuPDF with multi-column clustering; pages with little text or ≥35% image coverage automatically route through OCR.
- 3-Tier Excel Formula Evaluation: Resolves cached
.xlsxvalues first, then LibreOffice headless recalculation (sofficeonPATH), then pure-Pythonformulas, falling back to formula text with a warning if unresolved. - Limitations: Convert legacy
.xlsto.xlsxfirst; for pages mixing two unrelated writing systems (e.g. Vietnamese + Japanese on the same page), pass--ocr tesseractwith system language packs.