Export Markdown to PDF on a Mac

report.mdreport.pdf

Markdown is easy to write and awkward to hand to someone who does not use it. A PDF fixes that, but the Mac has no built-in Markdown-to-PDF route. Here are the usual workarounds, what each one asks of you, and how MarkPeek exports a themed PDF with a few clicks.

The Export as PDF sheet in MarkPeek with Paper options (Size, Orientation, Margins) and Document options (Layout, Appearance, Page numbers, Open in Preview when done)

Option 1: Print to PDF from whatever opens the file

Every Mac can print to PDF from the Print dialog. The catch is what gets printed. TextEdit and Quick Look print the raw source, so you end up with a PDF full of pound signs. A browser can print rendered Markdown, but only after you get the file onto a web page first, for example by viewing it on GitHub.

Where it falls down: the output is only as good as the page you print from, and you get the browser's headers, footers and page breaks.

Option 2: A code editor with a PDF extension

VS Code can export Markdown to PDF through extensions. It works, but you are installing an editor and an extension for a one-off task, and the output style is whatever the extension ships with.

Option 3: pandoc

pandoc is the powerful route and the one many people end up using. It converts Markdown to PDF, Word and dozens of other formats. PDF output needs a separate PDF engine, commonly a LaTeX distribution, which is a large install, and styling means writing templates or options.

brew install pandoc
pandoc report.md -o report.pdf

Where it falls down: for a single document you will spend more time on setup than on the export, and you get no preview of the result before it is written.

The MarkPeek way

MarkPeek exports PDF from the same renderer and theme you read the document in, so the exported PDF uses the same theme and renderer as the preview.

  1. Open the document and pick a theme from the Theme menu. Serif or Paper suit long reads; Plain suits anything that will be printed.
  2. Choose File ▸ "Export as PDF…" (⇧⌘E), or click "Export PDF" in the toolbar.
  3. In the sheet, set Paper: Size (A4, US Letter, US Legal or A5), Orientation (Portrait or Landscape) and Margins (None, Narrow, Normal or Wide).
  4. Set Document: Layout ("Pages" or "Single long page"), Appearance ("Follow theme", "Light" or "Dark"), "Page numbers" and "Title at the top of each page". Leave "Open in Preview when done" on to check the result right away.
  5. Click "Export…" and choose where to save. The default file name is the document name with a .pdf extension.
MarkPeek in Preview mode with the Paper theme in dark appearance, showing a drop cap and justified text

Choose the theme before you export

The theme decides the typeface, line length, heading style and colors of the PDF, so it is worth choosing before you export rather than fixing the result afterwards. Serif uses Charter with generous spacing and suits reports. GitHub gives underlined headings and grid tables. Plain is black on white with no decoration. If none fits, open the Theme Inspector (⌥⌘I), change the Type and Layout tabs, and use "Save As…". The "Theme" row in the export sheet is read-only and simply shows which theme will be used.

Faster repeat exports

MarkPeek remembers the options you used. "Export PDF Next to File" (⌥⇧⌘E) skips the sheet, reuses those options and saves the PDF next to the Markdown file. To change the starting values, open Settings (⌘,) ▸ Export: the "PDF defaults" section has Paper, Orientation, Margins, Layout and Appearance pickers and the "Open in Preview when done" toggle.

HTML and Print

File ▸ "Export as HTML…" (⌥⌘E) writes one self-contained .html file: the theme CSS and local images are embedded, and MathJax or Mermaid are included when the document uses them. There is no options dialog. File ▸ "Print…" (⌘P) prints through the same renderer, so you can use the standard Print dialog's own PDF menu as well.

These are the only export formats. MarkPeek does not export to Word (DOCX), PNG or EPUB; use pandoc if you need those.

Things to check before you send it

Frequently asked questions

Can macOS convert Markdown to PDF by itself?

Not as a built-in feature. You can print rendered Markdown from a browser, or use pandoc or an app such as MarkPeek.

Does the PDF look like the on-screen preview?

It uses the same theme and renderer. The PDF layout adds paper size, margins and optional page numbers, so page breaks and widths differ from the scrolling preview.

Can I export math and Mermaid diagrams to PDF?

Yes. Math and Mermaid render in the PDF export as they do in the app.

Can I choose the page size?

Yes: A4, US Letter, US Legal or A5, in Portrait or Landscape, with None, Narrow, Normal or Wide margins.

Related guides