How to convert a PDF to Markdown using pandoc

You can't do it directly: pandoc writes PDFs but doesn't read them. The usual workaround is to turn the PDF into a format pandoc reads (open it in Word, save as .docx, then run pandoc -f docx -t gfm), or to skip pandoc and use a PDF-aware tool such as pymupdf4llm or a PDF-to-Markdown API. Our page reader takes a PDF link and returns Markdown for $0.02.

Try it free Read Any Web Page, PDF or Doc — clean Markdown for AI agents · $0.02 / call

Why pandoc refuses the PDF

pandoc reads Markdown, HTML, Word, OpenDocument, LaTeX, EPUB and many more formats, but PDF isn't on its input list. When you run pandoc -o report.pdf it is going the other way, usually through a LaTeX engine.

The reason is the PDF format itself. A PDF stores characters at positions on a page, not paragraphs and headings. Something has to guess the structure back, and pandoc leaves that job to other tools.

Route 1: PDF to Word, then pandoc

  1. Open the PDF in Microsoft Word (File > Open). Word converts it to an editable document and warns that the layout may shift.
  2. Save it as report.docx.
  3. Run: pandoc -f docx -t gfm --wrap=none --extract-media=media report.docx -o report.md
  4. Check the headings. Word only marks them as headings if it recognised the big bold lines; otherwise they come out as plain bold text.

Route 2: pdftotext for plain text

You get the words in roughly the right places, but no headings, lists or links. pandoc can't add structure that isn't there, so this route suits searching and quoting, not clean Markdown.

pdftotext -layout report.pdf report.txt   # from poppler (brew install poppler, apt install poppler-utils)

Route 3: a converter that reads PDFs

pymupdf4llm turns a text PDF into Markdown in Python with one call (pymupdf4llm.to_markdown("report.pdf")). marker is heavier and uses machine-learning models for tricky layouts.

If the file is online, our page reader does it with one POST and the body {"url": "https://example.com/report.pdf"}: PDFs up to 10 MB, Word and PowerPoint files too, $0.02 per file. You're only charged when the file is read.

The routes compared

RouteHeadingsTablesEffort
Word, then pandocIf Word spots themOften keptManual step per file
pdftotextNoSpacing onlyOne command
pymupdf4llm or markerYesYes, for text PDFsPython setup
Page reader API (iamai.markets)YesYesOne request, $0.02

The product

Questions

Can pandoc turn Markdown into a PDF?

Yes, that direction works. It needs a PDF engine such as pdflatex, xelatex or weasyprint, set with --pdf-engine.

What about scanned PDFs?

They are pictures with no text layer, so every route above returns nothing useful. Add a text layer first with OCR (for example ocrmypdf), then convert.

Does the page reader keep the images?

No. It returns the text; pictures inside the PDF are left out.

Related

Updated 2026-12-01