Layout and typography · 9 min read
Markdown to PDF: 6 ways, and how to make it look designed
Convert Markdown to PDF with Pandoc, VS Code, Typora, your browser or a layout app. Compare page breaks, headers, fonts and tables, with exact commands.
To convert Markdown to PDF, render it with a tool that understands both formats. The fastest routes are Pandoc on the command line (pandoc notes.md -o notes.pdf), the Markdown PDF extension in VS Code, Export in Typora or Obsidian, or opening the rendered HTML in a browser and choosing Save as PDF. Pick by how much page control you need.
That is the short answer. The longer one matters because Markdown has no idea what a page is. It knows headings, paragraphs, lists and tables. Margins, page breaks, running headers, page numbers and fonts all come from whatever converts it, and that is where the methods differ. This guide compares six, gives the exact commands, and ends with what breaks and how to fix it.
Which Markdown to PDF method for which job
| Method | Best for | Page control | Cost |
|---|---|---|---|
| Pandoc + LaTeX | Technical docs, theses, scripted builds | High, via LaTeX variables | Free |
| Pandoc + WeasyPrint | Styling with CSS you already know | High, via CSS paged media | Free |
| VS Code Markdown PDF | READMEs and notes you already edit in VS Code | Medium: CSS, header and footer templates | Free |
| Typora or Obsidian | Writers who want one click | Low to medium, set by the theme | Typora paid, Obsidian free |
| Browser print to PDF | A one-off from any rendered page | Low | Free |
| Online converters | A quick file on a borrowed computer | Low | Free with limits |
| Layout app (Pengrid) | Reports, white papers, anything that must look designed | Full: grid, slots, page designs | Free |
Rule of thumb: if the PDF is for you or a developer, use Pandoc or VS Code. If it goes to a client, a board or a print shop, the converter is the wrong tool and you need a layout step.
Method 1: Pandoc with a LaTeX or HTML engine
Pandoc is a free command-line converter that reads Markdown and writes dozens of formats. It does not draw PDFs itself; it hands the job to a PDF engine you install separately. By default that engine is pdflatex, which means you need a LaTeX distribution (MacTeX, TeX Live or MiKTeX, or the smaller TinyTeX) before the first command works.
Pandoc with LaTeX
- Basic conversion: pandoc notes.md -o notes.pdf
- A4 paper with 25 mm margins: pandoc notes.md -o notes.pdf -V papersize=a4 -V geometry:margin=25mm
- Your own system fonts, which needs xelatex or lualatex: pandoc notes.md -o notes.pdf --pdf-engine=xelatex -V mainfont="Source Serif 4"
- Table of contents and numbered headings: pandoc notes.md -o notes.pdf --toc -N
- Several chapter files into one PDF, in order: pandoc 01-intro.md 02-method.md 03-results.md -o report.pdf
LaTeX produces excellent body text, with proper hyphenation, ligatures and justified lines that do not leave rivers. The cost is that changing the look means learning LaTeX templates or variables, and error messages from a missing package can be cryptic. If you only need a different font, the mainfont variable with xelatex covers most cases.
Pandoc with WeasyPrint or wkhtmltopdf
If you would rather style with CSS, ask Pandoc to go through HTML and pick an HTML-based engine:
- WeasyPrint: pandoc notes.md -o notes.pdf --pdf-engine=weasyprint --css=print.css
- wkhtmltopdf: pandoc notes.md -o notes.pdf --pdf-engine=wkhtmltopdf --css=print.css
WeasyPrint is the better choice today. It supports CSS paged media, so @page rules set the page size and margins, and margin boxes such as @bottom-center can hold counter(page) for page numbers. wkhtmltopdf still works, but the project has been archived and is no longer maintained, so do not build anything new on it. Pandoc also accepts typst as a PDF engine; Typst is a newer, much faster alternative to LaTeX worth a look if LaTeX install sizes put you off.
Method 2: VS Code Markdown PDF extension
VS Code has no built-in PDF export. The common route is the free Markdown PDF extension by yzane, which renders your file with Chromium and saves the result next to the source.
- Install Markdown PDF from the Extensions panel.
- Open the .md file.
- Open the command palette (Cmd+Shift+P on Mac, Ctrl+Shift+P on Windows) and run Markdown PDF: Export (pdf).
- Set paper size, margins and a custom stylesheet in Settings, under markdown-pdf.format, markdown-pdf.margin and markdown-pdf.styles.
It handles code highlighting well, which makes it the natural pick for developer documentation. Headers and footers are HTML templates in the settings, and page numbers come from the Chromium print classes pageNumber and totalPages. If no browser is installed, the first export downloads Chromium, so expect a pause and a few hundred megabytes on disk.
Method 3: Typora and Obsidian export
Markdown editors with a live preview can export what you see. In Typora, choose File, Export, PDF; the PDF uses the current theme, so a cleaner theme gives a cleaner PDF, and the export preferences add a header and footer. Typora is a paid app with a one-off licence. In Obsidian, open the note and choose Export to PDF from the file menu or the command palette. You get page size, margins and scaling, but no page numbers or running headers without a community plugin.
Both are the right answer for a writer who wants a tidy PDF of a note in five seconds. Neither gives you a layout: everything is one column, from top to bottom, and the theme decides how it looks.
Method 4: Print the rendered HTML from your browser
Any Markdown preview, a GitHub README, a rendered docs page or a local HTML file from pandoc notes.md -s -o notes.html, can be printed. Press Cmd+P or Ctrl+P, choose Save as PDF as the destination, and set paper size and margins under More settings. Turn off the browser's own headers and footers, or every page gets a URL and a date stamped in the corner.
This is quick and free, and it costs nothing to install. It is also the least controllable: page breaks fall wherever the browser decides, and sticky navigation and buttons from the web page come along unless the site has a print stylesheet.
Method 5: Online Markdown to PDF converters
Paste or upload Markdown, download a PDF. Online converters are fine for a public README on a computer where you cannot install anything. Read the privacy terms before uploading anything confidential: you are sending the full text of the document to someone else's server, and many free tools keep files for a period or add limits on size. Styling options are usually a theme picker and a page size.
Method 6: A layout app that keeps the Markdown
Every method above treats the PDF as a print of a web page: one column of text, poured top to bottom. That is fine for notes. It is not fine for a white paper, a report or a proposal, where readers expect a cover, a grid, figures placed next to the text they belong to, and running headers that tell them where they are.
The usual escape is to paste the Markdown into InDesign or Canva, at which point it stops being Markdown and every later edit is done by hand, twice. A layout app that keeps the Markdown as the source avoids that. In Pengrid, for example, you write in Writer, which is a plain Markdown editor, design pages on a grid in Design, and bind the text to slots with Merge. The text keeps changing; the layout stays put; the same source exports to a print-ready PDF or a self-contained HTML file.
Page breaks, running headers, page numbers and TOC
Markdown has no page break syntax. Each tool has its own workaround, and they do not travel between tools, so keep page breaks out of your source if you can and set them in the stylesheet or template instead.
| Method | Page break | Page numbers and headers | Table of contents |
|---|---|---|---|
| Pandoc + LaTeX | A line with \newpage | On by default; headers via the fancyhdr package | --toc |
| Pandoc + WeasyPrint | CSS: h1 { break-before: page; } | @page margin boxes with counter(page) | --toc |
| VS Code Markdown PDF | A line with <div class="page"/> | headerTemplate and footerTemplate settings | Not built in |
| Typora | Theme CSS or an HTML div | Export preferences | [toc] in the document |
| Obsidian | Plugin or CSS snippet | Plugin only | Plugin only |
| Browser | Print CSS only | Browser's basic header and footer | No |
| Pengrid | Each slot is on a page you designed | Set once in the universal layer | Designed as a page |
Break before every top-level heading in the stylesheet, not by hand in the text. A rule like h1 { break-before: page; } survives every edit; a hand-placed break ends up in the middle of a half-empty page after the next rewrite.
Fonts, images and tables: what breaks and how to fix it
Fonts
pdflatex cannot use your system fonts, which is why the default Pandoc PDF looks like a 1990s journal article. Switch to xelatex or lualatex and set mainfont. HTML engines use any font your CSS names, as long as it is installed or loaded with @font-face. Always check that the PDF embeds the fonts; in a PDF viewer, the document properties list them. For choosing the fonts themselves, see best fonts for reports.
Images
- Relative image paths resolve from the folder you run the command in. Run Pandoc from the Markdown file's folder, or pass --resource-path=images.
- Large images overflow the page in LaTeX. Give a width in the Markdown with Pandoc's attribute syntax, for example {width=80%}.
- Use 300 dpi images for print and PNG or SVG for charts. A JPEG screenshot of a chart blurs at every zoom level.
Tables
Wide tables are the most common failure. Text in LaTeX tables does not wrap unless the column widths are set, so a long cell runs off the page. In Pandoc, a pipe table where a row is longer than the column width setting gets relative widths and wraps; otherwise switch to grid tables or narrow the content. In HTML engines, add table { width: 100%; } and td { overflow-wrap: anywhere; } to the stylesheet. For tables that span pages, repeat the header row: HTML engines do this automatically for a thead, LaTeX needs the longtable package, which Pandoc uses by default.
Code blocks
Long lines of code do not wrap in most PDF outputs and get clipped at the margin. In CSS, set pre { white-space: pre-wrap; }. In LaTeX, the simplest fix is a smaller code font or shorter lines in the source.
A worked example
Take a ten-page project report written in Markdown: three chapters, two tables, four charts. Here is what each route costs to get it to a client-ready PDF.
- Pandoc with LaTeX: ten minutes once LaTeX is installed. Good body text, numbered headings and a TOC. Charts land where LaTeX floats them, sometimes a page later than the text that mentions them.
- VS Code: two minutes. Clean and readable, looks like a GitHub page. No cover, and no control over where charts fall.
- Browser print: one minute. Readable, but expect a table split across two pages and a heading stranded at the foot of a page.
- Layout app: an hour the first time to design the cover, the chapter opener and the body page. After that, the next report reuses the same pages and takes as long as the Markdown conversion.
If the document is going to be read by people who judge the work by how it looks, the layout hour pays back on the first report. If not, use Pandoc and move on. Either way, the page-level rules are the same; how to format a report has the margins, type sizes and heading levels.
Frequently asked questions
- How do I convert Markdown to PDF?
- Install Pandoc and a LaTeX distribution, then run pandoc file.md -o file.pdf. Without installing anything, open the rendered Markdown in a browser and print to PDF, or use the export in an editor such as VS Code, Typora or Obsidian.
- Can VS Code export Markdown to PDF?
- Not on its own. Install the free Markdown PDF extension, open the file, and run Markdown PDF: Export (pdf) from the command palette; the PDF is saved next to the Markdown file.
- How do I add a page break in Markdown?
- Markdown has no page break syntax, so it depends on the converter. With Pandoc and LaTeX, put \newpage on its own line; with HTML-based tools, use a CSS rule such as break-before: page on headings or on an empty div.
- How do I style Markdown when converting to PDF?
- With HTML-based converters, pass a CSS stylesheet, for example pandoc file.md -o file.pdf --pdf-engine=weasyprint --css=print.css. With LaTeX, set variables such as mainfont and geometry, or use a custom template.
- Is there a free Markdown to PDF converter?
- Yes. Pandoc, the VS Code Markdown PDF extension, Obsidian's export and every browser's Save as PDF are all free.
The easy writer
Tired of spending hours fixing the format in Word, or writing in Figma?
Pengrid keeps the words and the page apart. Write in a calm editor, design the pages once, and merge them.
In Word
An afternoon gone on images that jump, numbering that restarts and headers that won't stay put. One edit on page 3 and page 9 breaks.
In Figma
Beautiful pages, but every paragraph is a text box. Long text, outlines and rewrites were never what it was made for.
In Pengrid
Write the text, lay out the pages, bind them. Rewrite all week and the layout holds. Export a print-ready PDF.
Bring your own AI
Connect the Claude Code or OpenAI Codex sign-in you already have. No API key, no extra subscription.
Or keep it local
The built-in assistant runs on your computer, so your drafts never leave it. Works offline.
Free, no account needed. Teams €5 per person, free for now.