Pandoc PDF to Markdown: Why It Fails and What Works Instead
Pandoc PDF to Markdown: Why It Fails and What Works Instead
Pandoc is the Swiss-army knife of document conversion. It handles Markdown to HTML, DOCX to LaTeX, Markdown to PDF and dozens of other pairs. So when you need a PDF as Markdown, it seems like the obvious first stop.
The Short Answer: Pandoc Can't Read PDFs
PDF is an output format for Pandoc, not an input format. The manual lists the formats Pandoc can read with -f/--from (Markdown, HTML, DOCX, ODT, EPUB, LaTeX, RTF, PPTX, XLSX and more), and PDF is not among them. Pandoc can produce a PDF (through LaTeX or another engine), but it has no PDF reader.
So this command does not work:
pandoc input.pdf -o output.md
Pandoc stops with an error instead of producing Markdown. No flag changes that. If you want Pandoc in the loop, you first have to get the PDF into a format Pandoc can read.
Route 1: PDF to DOCX, Then Pandoc
This is the only route where Pandoc does real structural work.
1. Turn the PDF into a Word document. Microsoft Word opens PDFs directly: open the file, accept the prompt to convert it, then Save As .docx. Word rebuilds paragraphs, headings and simple tables as editable content. Results are good for text-based PDFs with simple layouts and weaker for complex ones.
2. Convert the DOCX with Pandoc:
pandoc input.docx -t gfm -o output.md --wrap=none --extract-media=./media
-t gfmwrites GitHub-flavoured Markdown, which supports pipe tables.--wrap=nonestops Pandoc from hard-wrapping lines, which makes the output cleaner for chunking and LLMs.--extract-media=./mediasaves the images from the DOCX into a folder and links them from the Markdown.
3. Automate it (for many files that are already DOCX):
import subprocess
from pathlib import Path
for docx in Path("docs").glob("*.docx"):
subprocess.run(
["pandoc", str(docx), "-t", "gfm", "--wrap=none", "-o", str(docx.with_suffix(".md"))],
check=True,
)
The weak link is step 1: the PDF-to-DOCX conversion is where layout problems (columns, complex tables) show up, and it's a manual step per file in Word.
Route 2: Extract Plain Text (No Structure)
If you only need the words, Poppler's pdftotext extracts the text layer:
# macOS: brew install poppler | Ubuntu: sudo apt-get install poppler-utils
pdftotext -layout input.pdf output.txt
This gives you plain text, not Markdown: no headings, no tables, and multi-column pages can interleave. Piping it through Pandoc doesn't add structure, because Pandoc has no way to know which lines were headings. For feeding an LLM a simple, single-column document, plain text is often good enough.
Route 3: A Dedicated PDF-to-Markdown Parser
If you need the structure (headings, lists, tables) without a manual Word step, use a tool built to read PDFs:
- file2markdown.ai: upload a PDF in the browser, no install. Text-based PDFs are parsed with pdf-inspector, which keeps headings, lists and tables as Markdown. Scanned PDFs are OCR'd on the Pro plan (up to 50 pages per file). Images inside PDFs are not extracted, so keep the original for charts and figures. AI assistants can also use it through the MCP server.
- PyMuPDF4LLM, Marker and Docling: open-source Python options you run yourself. See automating PDF to Markdown with Python for a working script.
Which Route Should You Use?
| Your situation | Best route |
|---|---|
| You already use Pandoc and have Word | Route 1: PDF to DOCX in Word, then pandoc -t gfm |
| You only need the raw words | Route 2: pdftotext |
| You need headings and tables, no install | Route 3: file2markdown |
| You need a scripted pipeline in Python | Route 3: PyMuPDF4LLM, Marker or Docling |
| The PDF is a scan | An OCR-capable tool (file2markdown Pro, Marker, Docling) |
For a broader comparison, see the file2markdown vs Pandoc comparison and our best PDF to Markdown converters roundup.
Frequently Asked Questions
Can Pandoc convert PDF to Markdown?
Not directly. PDF is not one of Pandoc's input formats, so pandoc input.pdf -o output.md fails. Convert the PDF to DOCX first (Word can do this) and then run Pandoc on the DOCX, or use a dedicated PDF parser.
Can Pandoc convert Markdown to PDF?
Yes. That direction works: pandoc input.md -o output.pdf produces a PDF using a LaTeX engine (or another PDF engine you choose with --pdf-engine).
Can Pandoc convert a scanned PDF?
No. Pandoc can't read PDFs at all, and it has no OCR. For scans you need an OCR-capable tool, such as file2markdown.ai on Pro, Marker, Docling, or Adobe Acrobat's export.
What is the best alternative to Pandoc for PDF to Markdown?
For no-install conversion with headings and tables, file2markdown.ai. For Python pipelines, PyMuPDF4LLM, Marker or Docling. The MarkItDown vs Pandoc post compares two popular converters in more detail.
The Bottom Line
Pandoc is excellent for everything it can read, and PDF isn't one of those formats. Either hand it a DOCX you've made from the PDF, or skip it and use a PDF parser. file2markdown's PDF to Markdown converter is the no-install option, and it flags likely conversion problems so you know what to check before the Markdown goes into a RAG pipeline.
The Markdown Memo
A fortnightly note for lawyers, researchers, accountants, and anyone else drowning in PDFs, scans, and decks. No spam.