---
title: "Markdown to PDF with headers, footers and page numbers on Mac"
author: Pedro Thomaz
source: https://coffeetext.app/blog/markdown-to-pdf-headers-footers-mac
---

# Markdown to PDF with headers, footers and page numbers on Mac

> Checked 28 November 2026 against the [pandoc manual](https://pandoc.org/MANUAL.html), [WeasyPrint's documentation](https://doc.courtbouillon.org/weasyprint/stable/) and Coffee's own help. I make Coffee, so weigh what I say about it. Coffee isn't affiliated with pandoc or WeasyPrint.

Markdown has no syntax for headers, footers or page numbers, so they always come from the tool that makes the PDF. On a Mac you have three practical ways to add them: pandoc with a little LaTeX, a stylesheet with CSS page rules, or an editor with PDF templates. In Coffee you pick a template that already has a header, page numbers and the date, or switch them on in the template editor, and press ⌘E.

What you want decides the route. If you need full control and don't mind code, LaTeX or CSS will do anything. If you want a report, a letter or a set of minutes to look right without writing any, a template is quicker.

## What counts as a header and a footer

- **A running header** is a line at the top of every page: the document's title, a company name, a logo, sometimes a chapter.
- **A footer** sits at the bottom: usually the page number, often "Page 3 of 12", sometimes the date.
- **A title page** comes first, and normally has no header, footer or number of its own.
- **Facing pages** are for print and binding: page numbers sit on the outer edge, so they swap sides from left to right pages.

Keep the header short. A long title in small type at the top of every page is noise, and on A4 or Letter a dozen words is about as much as reads well.

## With pandoc and LaTeX

pandoc's PDF route goes through LaTeX, and LaTeX has a standard package for headers and footers, `fancyhdr`. You load it through front matter or a small file passed with `--include-in-header`:

```
---
title: Quarterly report
header-includes:
  - \usepackage{fancyhdr}
  - \pagestyle{fancy}
  - \fancyhead[L]{Quarterly report}
  - \fancyhead[R]{Acme Ltd}
  - \fancyfoot[C]{\thepage}
---
```

Then:

```
pandoc report.md -o report.pdf
```

The strengths: it's free, it does anything LaTeX does, and it's repeatable from Terminal. The costs: you need a LaTeX install, which is large, and every change means learning a little LaTeX. "Page 3 of 12" needs another package, `lastpage`. The [pandoc manual](https://pandoc.org/MANUAL.html) explains `header-includes` and the other variables.

## With HTML and CSS page rules

The other route turns Markdown into HTML and prints it with an engine that understands CSS paged media, such as WeasyPrint. CSS has margin boxes for exactly this:

```css
@page {
  size: A4;
  margin: 2.5cm 2cm;
  @top-left { content: "Quarterly report"; font-size: 9pt; }
  @bottom-right { content: "Page " counter(page) " of " counter(pages); font-size: 9pt; }
}
@page :first { @top-left { content: none; } }
```

Then make the HTML with pandoc and print it:

```
pandoc report.md -s -o report.html
weasyprint report.html report.pdf
```

This is easier to style than LaTeX if you know CSS. One catch: browsers' own Print to PDF ignores most margin boxes, and adds their own header and footer with the URL and date instead, so use a paged-media engine like [WeasyPrint](https://doc.courtbouillon.org/weasyprint/stable/), not the browser. Pages that come out empty with this route are covered in [why a Markdown PDF export is blank](https://coffeetext.app/blog/why-is-my-markdown-pdf-blank).

## With a template in Coffee

Coffee, the Markdown editor I make, lays out its PDFs itself, and a PDF template decides how they look. [Markdown to PDF in Coffee](https://coffeetext.app/markdown-to-pdf) shows the templates on the page. Coffee comes with its own templates, and you can make yours or add more from a directory.

### Exporting with a template

1. Open the note and press ⌘E.
2. Pick a template from the Template menu, and a page size, A4 or Letter.
3. Turn the title page on or off.
4. Choose Export PDF.

### What a template can put on the page

In Settings, find PDF templates and choose Edit Templates…, or choose Edit… beside Template in the export panel. The editor shows a live page that changes as you go.

- **Header:** the note's title, your company name, or nothing, with a thin rule under it, on every page after the title page.
- **Logo:** none, left, middle or right, in the header and on the title page. Choose Image… picks your own.
- **Footer:** page numbers, written "Page 3 of 12", and the date, each switched on or off. The title page isn't counted.
- **Title page:** the note's title in the template's colour, with your name, the company and the date under it.
- **Facing pages, for a book:** a wider inner margin for the binding, and page numbers on the outer edge.
- **The rest of the look:** Sans, Serif, Mono or Typewriter type, the text size, the colour for headings and links, and Narrow, Normal or Wide margins.

Choose Save as New Template… to keep it under Yours, and Use for PDFs to make it the one your PDFs, prints and books use.

### Templates you can add

[The templates directory](https://coffeetext.app/templates) has layouts that add to Coffee in one click: Board paper has a title page, your logo, your company at the top, page numbers and the date; Field notes and Release notes have the date in the footer; Manuscript has a title page and page numbers; there are invoices, contracts with signature lines, Cornell notes with a cue column, two-column newsletters and a screenplay. Each opens in the editor, so you can change its header or footer before you use it.

What a template can't do, so you know before you start: there's no field for a header you type yourself beyond the title or the company, no different header per chapter, and no custom CSS. If you need those, the LaTeX or CSS routes above are the way. [Coffee's help on PDF templates](https://coffeetext.app/help/pdf) has the details.

## Which route to choose

- **One-off documents that need to look right:** a template. It's the fewest steps.
- **A report built the same way every week from a script:** pandoc, with either LaTeX or CSS, kept in a folder with the Markdown.
- **A house style with exact type and spacing:** CSS paged media, where you control every measure.
- **Something to edit after export:** Word. Coffee's Word export has real headings, lists and tables, and [Markdown to Word on a Mac](https://coffeetext.app/blog/markdown-to-word-docx-mac) covers it.

## Questions

### Can Markdown itself have a header or footer?

No. Markdown has no syntax for page furniture. Headers, footers and page numbers come from the tool that makes the PDF: a LaTeX package, CSS page rules, or an app's template.

### How do I add page numbers to a Markdown PDF?

With pandoc's LaTeX route they're on by default. Through HTML, use `counter(page)` in a CSS `@page` margin box. In Coffee, turn on Page numbers in the template, or pick one of the templates that has them.

### How do I show the page count, as in Page 1 of 10?

In LaTeX, load the `lastpage` package. In CSS, use `counter(page)` and `counter(pages)`. Coffee's page numbers are written that way already.

### Can I put my logo at the top of every page?

Yes. In LaTeX or CSS, add an image to the header. In Coffee's template editor, choose where the logo goes and pick your image with Choose Image….

### Does the title page get a page number?

Usually not. In Coffee the title page has no header or footer and isn't counted, so the first page of text is page 1.

---

Written by Pedro Thomaz, who makes Coffee, a Markdown editor for the Mac on macOS 15 or later, and for iPhone and iPad. It's free for 14 days with no card or account, then €3 a month, €29 a year, or €79 once with two years of updates. More at https://coffeetext.app/llms-full.txt
