Convert PDF to Markdown in Python (2026): 6 Libraries & VLM API Compared
KomoAI LLC · Updated · First published · 4 min read
The short answer: For clean, born-digital single-column PDFs, pymupdf4llm converts a file in milliseconds. For local CPU-only or air-gapped RAG pipelines with tables and scans, IBM Docling (MIT) is the strongest permissive default. For maximum local equation recovery on an NVIDIA GPU, use Marker or MinerU. And when you want zero GPU ops, reliable merged-cell tables, LaTeX math, and scanned OCR in one async call, route hard PDFs to a hosted VLM parser like the KolmoPDF PDF Parsing API.
Quick Comparison for Python Developers (2026)
| Option | License | Hardware | Scanned OCR | Complex Tables | LaTeX Math | Best Use Case |
|---|---|---|---|---|---|---|
| pymupdf4llm | AGPL / Commercial | CPU (fast) | ❌ No | ⚠️ Simple | ❌ No | Clean digital PDFs, fast pre-filtering |
| Docling (IBM) | MIT | CPU or GPU | ✅ Built-in | ✅ TableFormer | ⚠️ Flagged | Air-gapped / enterprise CPU RAG |
| Marker | Apache 2.0 + weight terms | GPU rec. | ✅ Surya OCR | ✅ Good | ✅ Yes | GPU batch jobs on academic papers |
| MinerU | MinerU Open Source | GPU rec. | ✅ 100+ langs | ✅ Very strong | ✅ Yes | Multilingual & scan-heavy corpora |
| MarkItDown | MIT | CPU (tiny) | ❌ External | ❌ Flattens | ❌ No | Mixed Office/HTML/audio ingestion |
| KolmoPDF API | Hosted REST / Skill / MCP | Zero local | ✅ Built-in | ✅ Pipe tables | ✅ $ / $$ | Zero-GPU high-fidelity papers & scans |
1. PyMuPDF4LLM (Fastest Local Text-Layer Default)
pip install pymupdf4llm
import pymupdf4llm
md = pymupdf4llm.to_markdown("paper.pdf")
with open("paper.md", "w", encoding="utf-8") as f:
f.write(md)
Built on PyMuPDF specifically for LLM ingestion (page_chunks=True emits RAG-ready chunks).
Where it breaks: Image-only scanned PDFs return empty text, equations degrade into broken Unicode glyphs, and two-column papers with floating figures can interleave columns.
2. Docling by IBM (Best MIT CPU-Friendly Local Parser)
pip install docling
from docling.document_converter import DocumentConverter
converter = DocumentConverter()
result = converter.convert("paper.pdf")
with open("paper.md", "w", encoding="utf-8") as f:
f.write(result.document.export_to_markdown())
Why developers pick it: Permissive MIT license, runs cleanly on CPU without requiring a GPU, detects scanned pages automatically, and preserves strong table structure. For formula enrichment, enable Docling’s formula options (note heavier runtime on CPU).
3. Marker & MinerU (Best Local GPU Fidelity)
# Marker
pip install marker-pdf
marker_single paper.pdf --output_dir out/
# MinerU
pip install "mineru[all]"
mineru -p paper.pdf -o out/
Both chain layout detection, OCR, and equation models to recover two-column reading order and LaTeX math locally.
Trade-offs: Heavy PyTorch/model-weight downloads (multiple GBs), 4–8 GB+ VRAM for comfortable throughput, and non-MIT model-weight terms (Marker restricts free weights above $5M funding/revenue; MinerU uses its own open-source license).
4. MarkItDown (Microsoft — Multi-Format Ingestion)
pip install markitdown
from markitdown import MarkItDown
md = MarkItDown()
result = md.convert("deck_or_doc.pdf")
print(result.text_content)
Great when one Python pipeline ingests .docx, .pptx, .xlsx, .html, and simple PDFs under an MIT license. For complex PDFs, its default path does not emit Markdown heading hierarchies, tables, or LaTeX formulas.
5. pdfplumber (Coordinate-Level Table Extraction)
import pdfplumber
with pdfplumber.open("invoice.pdf") as pdf:
for page in pdf.pages:
print(page.extract_text())
for table in page.extract_tables():
print(table)
Best for fixed-layout invoices and forms where you want exact cell coordinates rather than flowing Markdown.
6. KolmoPDF VLM Parsing API (Zero-GPU Async Jobs & AI Agent Skill)
When you do not want to host GPU inference servers—or when pymupdf4llm scrambles two-column papers, formulas, and merged-cell tables—the KolmoPDF PDF Parsing API runs a Visual Language Model over each page image asynchronously (202 Accepted + job polling/webhook/SSE):
import os
import time
import requests
API = "https://www.kolmopdf.com"
headers = {"Authorization": f"Bearer {os.environ['KOLMOPDF_API_KEY']}"} # create at /api-keys
# 1) Submit job (supports up to 300 MB / 800 pages)
with open("paper.pdf", "rb") as f:
created = requests.post(
f"{API}/api/v1/jobs/parse",
headers=headers,
files={"file": f},
data={"table_mode": "markdown"},
timeout=60,
)
created.raise_for_status()
job_id = created.json()["id"]
# 2) Poll until terminal status (or configure webhook_url / SSE)
while True:
status = requests.get(f"{API}/api/v1/jobs/{job_id}", headers=headers, timeout=30).json()
if status["status"] in ("succeeded", "failed", "cancelled"):
break
time.sleep(2)
if status["status"] != "succeeded":
raise RuntimeError(status.get("error") or status)
# 3) Download Markdown or ZIP (inspect result.filename / Content-Disposition)
result = requests.get(f"{API}/api/v1/jobs/{job_id}/download", headers=headers, timeout=60)
result.raise_for_status()
with open("paper_result.md", "wb") as out:
out.write(result.content)
- AI Agents (Claude Code / Codex / Cursor): Install the official standalone skill with
npx skills add komoai2026/kolmopdf-skill(Node.js 20+) or the MCP server (@kolmopdf/mcp-server). - Pricing & Privacy: 2 credits/page (3 with inline translation into 9 languages); 300 free credits on signup + 50 daily credits; PAYG $3 per 1,000 credits; Web, API, and MCP share one balance. Uploaded PDFs are never used for AI training (Security policy).
Production Pattern: Hybrid Local + VLM Escalation
If you are processing hundreds or thousands of PDFs for RAG, do not send clean single-column memos to a VLM, and do not trust text-layer extraction on scanned papers:
- Pre-check locally with
pymupdf4llmor PyMuPDF: Count extracted characters per page. If a 10-page PDF yields< 100characters per page, it is scanned. - Escalate hard documents: Route scans, low-text pages, or dense scientific papers (detected via math symbols / multi-column bounding boxes) to Docling (if air-gapped) or KolmoPDF API (if you want zero GPU ops and full LaTeX + merged tables).
FAQ
What is the fastest Python library to convert PDF to Markdown?
pymupdf4llm.to_markdown("file.pdf") for clean digital PDFs. For complex layouts, throughput matters less than downstream RAG retrieval quality.
How do I batch convert several PDF documents to Markdown?
Loop files locally with Docling/pymupdf4llm, or submit concurrent jobs to /api/v1/jobs/parse (KolmoPDF returns 202 Accepted immediately so you can submit a folder of PDFs and collect results via webhooks or polling).
Want a broader non-Python comparison? Read our 10-tool Best PDF to Markdown Converters benchmark or our tables and LaTeX formulas tutorial.