Guide
How to Add Page Numbers, Headers and Footers to a Markdown PDF
Markdown has no concept of a "page" — it's just text. So page numbers, running headers, and footers are added by the tool that lays your document onto paper, not by the Markdown itself. That means how you get them depends entirely on how you convert. This guide covers the three practical routes and the trade-offs of each.
The easy route: your browser's print dialog
Every browser can add page numbers and a header/footer when it saves a PDF — and it's the simplest option by far.
- Render your Markdown (in a converter's preview, a VS Code preview, or any page).
- Press
Ctrl/Cmd + P. - Set the destination to Save as PDF.
- Open More settings and enable Headers and footers.
- Save.
With that checkbox on, the browser stamps the page number, the date, the document title, and the URL into the page margins. It's zero-config and works everywhere — the catch is you get the browser's fixed format, not fully custom text.
Getting the filename and title right matters here, because the browser often uses the document's title in the header and as the default filename. A converter like ConvertMDapp sets a sensible document title for you, so the saved PDF is named and labelled correctly. Everything runs in your browser, so the document is never uploaded.
Full control: Pandoc with LaTeX
If you want custom headers and footers — a specific footer text, "Page X of Y", a company name in the corner — Pandoc with a LaTeX engine gives you complete control via the fancyhdr package:
pandoc report.md -o report.pdf \
-V header-includes='\usepackage{fancyhdr}\pagestyle{fancy}\fancyhead[L]{My Report}\fancyfoot[C]{\thepage}'
That puts "My Report" in the top-left of every page and the page number centered in the footer. You can set left/center/right slots in both the header (\fancyhead[L/C/R]) and footer (\fancyfoot[L/C/R]). The cost is the LaTeX toolchain and a bit of syntax — but nothing else matches it for precise, repeatable output.
Middle ground: wkhtmltopdf
If you convert through wkhtmltopdf (Markdown → HTML → PDF), it has dedicated footer/header flags with placeholder tokens:
wkhtmltopdf --footer-center "Page [page] of [topage]" --footer-font-size 9 report.html report.pdf
Tokens like [page], [topage], [title], and [date] get substituted per page. It's less setup than LaTeX and more flexible than the browser dialog — a reasonable middle ground if you already have an HTML step.
A note on CSS @page margin boxes
CSS defines a proper way to do this — @page margin boxes with content: counter(page) — and it's the "right" answer in theory:
@page {
@bottom-center { content: "Page " counter(page); }
}
The reality: browsers don't support the @page margin boxes for print (only dedicated engines like Prince or WeasyPrint do). So in a normal browser-based conversion, this CSS is silently ignored — use the print dialog's headers/footers checkbox instead. It's worth knowing so you don't spend an hour on CSS that can't work in your tool.
Which route fits?
| Need | Best route |
|---|---|
| Quick page numbers, any device | Browser Print → Headers and footers |
| Custom text, "Page X of Y", branding | Pandoc + LaTeX (fancyhdr) |
| Placeholder tokens without LaTeX | wkhtmltopdf footer flags |
| Custom text in a plain browser tool | Not possible — use one of the above |
For most people, the browser dialog's built-in headers and footers are all they need. Reach for Pandoc or wkhtmltopdf only when you need specific text or a house style.
If you're setting up the conversion itself, start with the complete Markdown-to-PDF guide, and see page numbers' cousin — a clickable table of contents for navigating long documents.
FAQ
How do I add page numbers to a Markdown PDF?
The simplest way: when you Save as PDF from your browser, open More settings and turn on Headers and footers — the browser adds page numbers automatically. For custom numbering, use Pandoc with the fancyhdr LaTeX package or wkhtmltopdf's footer flags.
Can I put custom footer text on every page from a browser tool? Not with the browser's built-in dialog, which only offers its fixed header/footer format. For custom text on every page, convert with Pandoc + LaTeX or wkhtmltopdf.
Why is my @page footer CSS ignored?
Browsers don't implement CSS @page margin boxes for printing — only dedicated print engines do. In a browser-based conversion, use the print dialog's headers/footers option instead.