How to Export Markdown to PDF and Word with Pandoc
Quick answer
To export a Markdown file to Word, run pandoc input.md -o output.docx. To export to PDF, run pandoc input.md -o output.pdf. Both read the same source file — the only difference is the output extension, which pandoc uses to pick the converter.
The one thing to know going in: Word export works out of the box, but PDF export needs a rendering engine installed first (more on that below). If you ever need to go the other way — turning a Word doc or a Google Doc into Markdown — that's a pandoc command too, and it's worth bookmarking alongside this one since the two often get used together on the same document.
Step-by-step
Exporting to Word (.docx)
The base command is:
pandoc input.md -o output.docxThat produces a valid, readable Word document — but with pandoc's own generic default styling: plain heading fonts, default margins, no branding. Fine for an internal draft, and you're done. Need it to match a house style instead? Pandoc gives you a template system rather than manual formatting in Word after every export.
First, generate pandoc's own reference template:
pandoc -o custom-reference.docx --print-default-data-file reference.docxOpen custom-reference.docx in Word or LibreOffice Writer, and edit the existing styles pandoc uses for headings, body text, tables, and hyperlinks — don't create new style names, just change what's already there (pandoc's own docs recommend the same approach). Save it, then point future conversions at it:
pandoc input.md --reference-doc=custom-reference.docx -o output.docxKeep a couple of these around — one per client, one per report type — and swap the --reference-doc path as needed. Drop one named reference.docx into your ~/.pandoc folder and pandoc applies it automatically without the flag at all.
A YAML metadata block at the top of your Markdown file carries straight through into the DOCX document-properties fields:
---
title: "Q3 Migration Report"
author: "Jordan Lee"
date: 2026-07-08
---Title, author, and date show up in the exported file's properties automatically — no need to set them by hand in Word afterward.
Exporting to PDF
The base command looks the same:
pandoc input.md -o output.pdfThe difference is that pandoc doesn't render PDF itself — it hands the job to a separate PDF engine, and by default that's a LaTeX engine (pdflatex). If you don't already have LaTeX installed, that first PDF export will fail. You have two options: install a LaTeX distribution (MacTeX on Mac, MiKTeX on Windows, TeX Live on Linux), or skip LaTeX entirely and pick a lighter engine with the --pdf-engine flag:
pandoc input.md --pdf-engine=weasyprint -o output.pdfOther valid values include wkhtmltopdf, prince, and typst — see the full list of supported engines in pandoc's manual. Each has its own install, and all of them are smaller than a full LaTeX distribution.
Pandoc's own getting-started guide walks through this same base-command pattern — the -o extension is doing all the format-selection work in every example, from HTML to LaTeX to DOCX to PDF.
Add -s (short for --standalone) if you want the output wrapped as a complete document rather than a bare content fragment — worth knowing for HTML and LaTeX intermediate output, though DOCX and PDF are standalone by default.
One thing worth doing before you export either format: keep the source file itself well-structured. Clean, consistently-nested headings translate into a cleaner table of contents and section breaks in both Word and PDF. If the source document is long, it's worth outlining it in Markdown with headings that stay navigable before you run the export at all — messy source headings turn into a messy exported document either way.
Common problems and fixes
- "pdflatex not found" or a similar engine error. Pandoc's default PDF path needs a LaTeX engine on your machine. Either install one (MacTeX, MiKTeX, TeX Live) or switch engines:
pandoc input.md --pdf-engine=weasyprint -o output.pdf. - The Word doc looks plain or uses the wrong fonts. That's pandoc's default styling, not a bug. Build a
--reference-doctemplate from your own edited copy of pandoc's default reference file and pass it in on export. - Title, author, or date are missing from the exported file. Add a YAML metadata block at the top of the Markdown source — pandoc reads it and writes those fields into the output automatically.
- Exported output looks like a fragment, missing headers or footers. Add
-s/--standaloneto the command.
Doing this with Carets
Carets keeps every note and document as a plain Markdown file — nothing proprietary, nothing locked into an app-specific format. That matters here specifically: the moment you need a Word doc for a reviewer or a PDF for printing, the source file is already exactly what pandoc expects. No export-then-reformat step, no copying content out of a rich-text editor first.
A few features make this workflow smoother day to day. Files, projects, and tags keep drafts organized so you can find the right Markdown file fast when it's time to export it. Native performance on iPhone, iPad, and Mac means opening and editing that file — wherever you're writing from — doesn't feel like waiting on a web app. And because everything stays plain text, your source material for pandoc conversions today is just as usable in whatever tool you're using five years from now.
If this is part of a broader habit of capturing notes and documents in plain text, it's worth looking at a plain-text note-taking system built around the same portability. Carets is free to try on the App Store for iPhone, iPad, and Mac.
Frequently Asked Questions
Do I need to install anything besides pandoc to export to PDF?
Yes, usually. Pandoc doesn't render PDF itself — it hands off to a PDF engine. By default that's a LaTeX engine like pdflatex, which means installing a LaTeX distribution (MacTeX, MiKTeX, or TeX Live). If you don't want a multi-gigabyte LaTeX install, pass --pdf-engine=weasyprint, wkhtmltopdf, or typst instead, each with its own lighter install.
Why does my exported Word document look plain and generic?
Because pandoc's default docx output uses its own minimal built-in styles. To match a house style, generate pandoc's default reference template, edit its heading and paragraph styles in Word or LibreOffice, and pass it back in with --reference-doc on future conversions.
Can I control the title, author, and date that show up in the exported file?
Yes — add a YAML metadata block at the top of your Markdown file with fields like title, author, and date. Pandoc reads that block and writes the values into the DOCX document-properties fields (and into PDF metadata) automatically, so you don't have to set them by hand after exporting.
What's the actual command to convert a Markdown file to Word or PDF?
For Word: pandoc input.md -o output.docx. For PDF: pandoc input.md -o output.pdf (add -s/--standalone if you want a fully wrapped document rather than a bare fragment). Pandoc infers the format from the file extension, so you rarely need -f or -t.
Conclusion
Exporting Markdown with pandoc comes down to two commands — one for Word, one for PDF — plus two things worth setting up once: a --reference-doc template so Word output matches your style, and a YAML metadata block so title, author, and date travel with the file automatically. Keep your source material in plain Markdown, and you can export it to whatever format the person on the other end actually needs, whenever they need it.