How to Convert PDF to Markdown (Step by Step Guide)
Step-by-step guide to converting PDF documents to clean Markdown. Compare multiple methods and find the approach that works for your document type.
PDF to Markdown conversion is notoriously difficult. PDFs were designed for print layout, not text extraction. Here's how to do it right.
Why PDF Conversion Is Hard
PDFs store text as positioned glyphs, not structured content. There's no concept of "heading" or "paragraph" in a PDF — just characters at specific coordinates. This means:
- Headings must be inferred from font size and position
- Tables are just aligned text without cell boundaries
- Multi-column layouts confuse extractors
- Scanned PDFs require OCR
- Embedded fonts can produce garbled text
Method 1: DocsToMarkdown (Easiest)
For text-based PDFs (not scanned images), the simplest approach:
- Go to DocsToMarkdown.com
- Drag your PDF onto the converter
- Download the .md file
The converter uses PDF.js under the hood for accurate text extraction, then applies heuristics to detect paragraphs, headings, and structural elements. It's not perfect — complex layouts may need manual cleanup — but it handles most documents well.
Method 2: Pandoc + pdftotext
For command-line users:
pdftotext -layout document.pdf - | pandoc -f plain -t markdown -o output.md
The -layout flag preserves the visual layout of the text, which helps with table alignment. This method works best for single-column documents with simple formatting.
Method 3: OCR for Scanned PDFs
If your PDF contains scanned images (no selectable text), you need OCR:
-
Tesseract (free, open-source):
tesseract scanned.pdf output -l eng txt -
Adobe Acrobat Pro (paid): Built-in OCR with better accuracy for complex layouts
-
Google Cloud Vision / AWS Textract (paid API): Best accuracy for large-scale processing
After OCR, you'll have plain text that can be formatted as Markdown.
Handling Multi-Column Layouts
Multi-column PDFs are the hardest case. The text extraction order often interleaves columns instead of reading left-to-right per column. Solutions:
- Manual approach: Extract text, then reorder paragraphs
- Layout-aware tools: PDF.js can extract text by position and detect columns
- Two-pass: First extract all text, then use heuristics to group by column position
Preserving Tables from PDFs
Tables in PDFs are just aligned text. To extract them:
- Extract text with position data (x, y coordinates per character)
- Cluster text by y-coordinate to identify rows
- Within each row, cluster by x-coordinate to identify cells
- Build the Markdown table from cell clusters
DocsToMarkdown implements this approach. Results vary by PDF quality — well-structured tables extract cleanly, while heavily formatted or merged-cell tables may need manual adjustment.
Tips for Better Results
- Prefer native formats over PDF — if you have the original .docx or .html, convert from that instead
- Use single-column layouts — reformat multi-column documents before exporting to PDF
- Embed fonts — missing fonts cause garbled character extraction
- Avoid scanned PDFs when possible — OCR is inherently lossy
- Review the output — always spot-check headings, tables, and special characters