All posts

How to Convert PDF to Markdown

Every practical way to convert PDF to markdown — purpose-built extractors, OCR for scans, AI tools, and online converters — plus what to check before you trust the output.

Short answer: To convert PDF to markdown, use a tool built for document extraction rather than a generic file converter. For text-based PDFs, pymupdf4llm is the fastest option and Marker or Docling produce better structure. Scanned PDFs need OCR first. Pandoc cannot do it — Pandoc does not read PDF as an input format. No method is fully accurate, so budget time to fix headings and tables by hand.

PDF to markdown is the one document conversion that never feels solved. Word to markdown is fine. HTML to markdown is fine. PDF fights back, and the reason is structural rather than a gap in the tooling.


Why PDF Is Hard to Convert

A PDF is a description of where marks go on a page. "Draw the glyph H at coordinate 72, 640 in 18pt Helvetica Bold." It is a layout format with no obligation to record that those glyphs form a heading, that this block is a table cell, or that the left column continues on the next page rather than into the right column.

Markdown is the opposite: pure structure, no layout. Converting one to the other means inferring semantics that were thrown away when the PDF was made.

Every converter is guessing at the same set of questions:

  • Is this line a heading, or just a bold sentence? Converters usually infer heading levels from font size and weight, which fails on documents with inconsistent styling.
  • What's the reading order? Two-column academic papers, sidebars, and pull quotes routinely come out interleaved.
  • Where does a paragraph end? PDFs store hard line breaks per visual line, so naive extraction gives you a break after every line and hyphens stuck mid-word.
  • Is this whitespace a table, or two paragraphs side by side?
  • Are these characters at all? A scanned PDF is a picture of text.

Knowing that, the differences between tools make more sense: they're all trading speed against how much inference they attempt.


Method 1: Purpose-Built Extractors (Best Results)

These are Python tools designed specifically to turn documents into markdown for reading, search, or feeding to an LLM.

PyMuPDF4LLM is the fastest and simplest. It's rule-based — no models to download — and does a good job on clean, digitally generated PDFs with a single column.

pip install pymupdf4llm
import pymupdf4llm
md = pymupdf4llm.to_markdown("report.pdf")
open("report.md", "w").write(md)

Marker uses machine learning models for layout detection, which makes it far better at multi-column documents, headers and footers, equations, and tables. It's slower, and it wants a GPU to be comfortable, but the output usually needs less cleanup.

pip install marker-pdf
marker_single report.pdf --output_dir out/

Docling (from IBM Research) takes a similar model-driven approach with strong table structure recognition, and handles more input formats than just PDF.

pip install docling
docling report.pdf --to md

MarkItDown (from Microsoft) is a general-purpose "anything to markdown" utility. Its PDF path is basic text extraction, so it's a reasonable choice for simple documents and a poor one for anything with columns or tables.

For a one-off conversion of a simple document, start with PyMuPDF4LLM. For a report you'll be living with, or a batch of them, Marker or Docling will save you more time than they cost.


Method 2: Ask an AI Tool

Uploading a PDF to Claude or ChatGPT and asking for markdown works surprisingly well for short documents — often better than the extractors on structure, because the model understands what a heading is instead of guessing from font size.

The tradeoffs are real:

  • It may paraphrase. A model asked to "convert" can quietly summarize, tidy prose, or drop a row from a table. If you need the text verbatim, say so explicitly and spot-check against the original.
  • Length limits. A 300-page manual won't come back whole. Split it.
  • Non-determinism. Run it twice, get two slightly different files. That's a problem for pipelines, not for one-off conversions.
  • Confidentiality. Same caution as any upload.

Where AI genuinely wins: messy documents where you want usable markdown rather than a faithful transcript — a scanned slide deck turned into notes, a contract turned into an outline. This is a big part of why AI tools use markdown as their default output format in the first place.


Method 3: Online Converters

Search "pdf to markdown" and you'll get a dozen web-based converters. They're convenient and they cost nothing.

Two things to weigh. First, quality: most are running a basic text extraction under the hood, which means the same weaknesses as the simplest command-line tools — broken columns, no real table structure, headings guessed or missing. Second, and more important: you are uploading the document to someone else's server. For a public PDF that's fine. For a contract, a medical record, or anything under NDA, use a local tool instead.


What About Pandoc?

Pandoc is the standard answer for document conversion, so it's worth being explicit: Pandoc cannot read PDF. PDF is an output format for Pandoc, not an input one. Running pandoc report.pdf -o report.md fails or produces garbage.

Pandoc is the right tool for the other direction, and for DOCX, HTML, LaTeX, EPUB, and RTF as inputs. If your PDF started life as a Word document, converting the original .docx with Pandoc will beat any PDF extractor by a wide margin. Always look for the source file first.


Scanned PDFs Need OCR

If you can't select text in Preview, there is no text in the file — just images of text. No extractor can help until OCR runs.

OCRmyPDF adds a searchable text layer to an existing PDF, after which any of the tools above will work:

brew install ocrmypdf
ocrmypdf scan.pdf scan-ocr.pdf

Marker and Docling include their own OCR models and can go straight from a scan to markdown, which is usually the better path for a document you only need once.

Expect OCR-specific errors on top of the usual conversion problems: l versus 1, rn read as m, dropped diacritics, and confident nonsense where the scan is skewed or the page is stamped. Proofread anything that matters.


Tables Are the Hardest Part

Every conversion tool is at its worst on tables, and the reason is the same structural problem in miniature. A PDF table might have no ruling lines, merged header cells, a row that wraps to two visual lines, or a continuation across a page break with the header repeated.

Markdown pipe tables, meanwhile, can't express merged cells or multi-line content at all. Even a perfect extraction has nowhere to put a rowspan.

What to do about it:

  • Check every table by hand. Column counts, row counts, and whether wrapped cells got split into extra rows.
  • Simplify. Flatten merged headers into a single row. Use <br> inside a cell for content that has to wrap, which is the one thing pipe tables do support.
  • Consider HTML for genuinely complex tables if your renderer allows it, or keep the table as an image with the data in a linked CSV.

Comparison

MethodSetupQuality on clean PDFsColumns and tablesScansPrivacy
PyMuPDF4LLMOne pip installGoodWeakNoLocal
Markerpip install, models downloadVery goodGoodBuilt-in OCRLocal
Doclingpip install, models downloadVery goodStrong tablesBuilt-in OCRLocal
MarkItDownOne pip installBasicWeakNoLocal
AI tool (Claude/ChatGPT)NoneGood structure, may paraphraseDecentOften yesUploaded
Online converterNoneBasicWeakVariesUploaded
PandocN/ANot supported as input

What to Check in the Output

Whatever tool you used, open the resulting .md and go through this list before you trust it:

  1. Heading levels. Converters over-produce ## from bold body text and under-produce structure from styled headings. Fix the hierarchy first — everything downstream depends on it.
  2. Reading order. Skim for sentences that stop mid-thought and resume three paragraphs later. That's a column mis-order.
  3. Hyphenation. Search for - at line ends and for words split across lines.
  4. Line breaks. Some tools emit a hard break after every visual line. Reflowing those into paragraphs is the single biggest readability win — see markdown line breaks for what those breaks actually mean.
  5. Tables. Every one, individually.
  6. Page furniture. Running headers, footers, and page numbers usually survive as stray lines throughout the document.
  7. Math. Formulas become gibberish unless the tool emits LaTeX. Marker and Docling attempt it; check the output against LaTeX math in markdown.
  8. Images. Confirm they were extracted to a folder and that the relative paths in the markdown actually resolve.

Reading and Fixing the Result

Conversion gets you a .md file that needs editing — usually quite a lot of it. That's where a proper markdown editor earns its place: you want to see the rendered structure and the raw source of the same document without switching apps, because most of the cleanup is structural.

OpenMark opens the converted file, renders headings, tables, code blocks, and math in Document view, and drops into a raw source editor when you need to repair a table or collapse a hundred stray line breaks. It doesn't do the PDF conversion itself — use the tools above for that — but it's where the output becomes readable. And when you need to go back the other way, it exports to PDF and HTML directly.


Download OpenMark → — $9.99, one-time, native macOS. Open your converted .md file, see exactly what the extractor produced, and fix it in place.