The most reliable free way to convert Markdown to PDF, Word, or HTML is Pandoc, a command-line converter. Install it, open a terminal in the folder with your file, and run one of these:
# Markdown to HTML (a complete web page) pandoc notes.md -f gfm -s -o notes.html # Markdown to Word pandoc notes.md -f gfm -o notes.docx # Markdown to PDF (needs a PDF engine; Typst is the easiest) pandoc notes.md -f gfm --pdf-engine=typst -o notes.pdf
Rather not use the command line? In VS Code, the free Markdown PDF extension exports to PDF and HTML with a right-click. Google Docs can turn pasted Markdown into a document that you then download as Word or PDF. If you just received an .md file and want to know what it is, start with my beginner guide, What is an .md file?
I ran every command on this page on my Mac in October 2026, with Pandoc 3.12.1, Typst 0.15.1, WeasyPrint 70.0, and Tectonic 0.17.0 (a LaTeX engine). I opened the Word files in LibreOffice and looked inside them to check the styles. Apps I couldn’t test myself (the VS Code extension, Typora, Obsidian, Word) are described from their official documentation, and I say so when I do that.
Which method should you use?
| You want | Easiest way | Most control |
|---|---|---|
| One PDF, right now | VS Code + Markdown PDF, or print from your browser | Pandoc with Typst or LaTeX |
| A Word document | Google Docs: Paste from Markdown, then download as .docx | Pandoc with a reference document for your styles |
| An HTML page | Markdown PDF: Export (html) | Pandoc with -s, --css and --embed-resources |
| Slides or an e-book | Your Markdown editor’s export, if it has one | Pandoc (.pptx and .epub) |
| HTML inside your own website or app | A Markdown library | markdown-it or marked |
| Dozens of files | Not by hand | Pandoc in a loop with a defaults file |
Quick options without the command line
Google Docs (for Word and PDF)
Google Docs can convert Markdown when you paste it: turn on Tools > Preferences > Enable Markdown, copy the raw text of your file, and right-click > Paste from Markdown. Then choose File > Download > Microsoft Word (.docx) or PDF Document. It’s the easiest route for a non-technical colleague. I walk through it step by step in how to convert an .md file to Word, Google Docs, or PDF, so I won’t repeat it here. If your Markdown is an AI answer on your clipboard, see my guide to pasting ChatGPT and Claude answers.
VS Code: the Markdown PDF extension
VS Code’s built-in Markdown preview has no print or export command (I checked the VS Code Markdown docs; there’s nothing about PDF). For that you need an extension, and the popular one is Markdown PDF by yzane. It’s still actively maintained: version 2.2.0 came out in July 2026. According to its README:
- Install the extension and open your .md file.
- Right-click in the editor and choose Markdown PDF: Export (pdf). There are also commands for html, png, jpeg, and “all”.
- The PDF appears next to your Markdown file.

Behind the scenes, it prints with Chrome or Edge if you have one installed, and otherwise downloads its own Chromium on first use. A few settings worth knowing (they go in your VS Code settings.json):
"markdown-pdf.format": "A4", "markdown-pdf.margin.top": "1.5cm", "markdown-pdf.margin.bottom": "1cm", "markdown-pdf.margin.right": "1cm", "markdown-pdf.margin.left": "1cm", "markdown-pdf.convertOnSave": true
The extension also renders Mermaid diagrams (it loads the Mermaid library from a CDN by default), and you force a page break with <div class="page"/>. Since version 2.1.0 it strips risky raw HTML such as <script> by default, so don’t be surprised if some HTML in your Markdown disappears from the PDF. I haven’t run the extension myself for this article; this is all from its README.
Typora and Obsidian
If you write in a Markdown editor, check its export menu first:
- Typora exports to PDF, HTML, and images by itself (File > Export). For Word, OpenDocument, EPUB, LaTeX, and more, it uses Pandoc, which you have to install separately (Typora’s export docs).
- Obsidian has Export to PDF in the command palette and in a note’s More options menu, with settings for page size, landscape, margins, and scaling. It’s desktop only, and exports always use light styling (Obsidian Help). Obsidian has no built-in Word export; community plugins fill that gap, usually by calling Pandoc.
Print from your browser
Anything that shows your Markdown as a web page can become a PDF: open it in Chrome, Edge, Firefox, or Safari, press Ctrl+P (Cmd+P on a Mac), and choose Save as PDF. That works for a Markdown file on GitHub, for the HTML export of any editor, and for the Pandoc HTML file I make below. Turn off “Headers and footers” in the print dialog if you don’t want the date and file path on every page.
Online converters: mind your privacy
Search for “markdown to pdf” and you’ll find dozens of websites that convert a file in your browser. Some do everything locally, but many upload your text to their server, and you can rarely tell which. That’s fine for a public README. It’s not fine for contracts, customer data, medical or financial details, or anything your employer considers confidential. For those, use a tool that runs on your own computer: everything else on this page does.
Pandoc: install it and tell it which Markdown you have
Pandoc is free and open source, and converts between dozens of formats. The installation page has installers for Windows and macOS, or use a package manager:
# macOS (Homebrew) brew install pandoc # Windows winget install --source winget --exact --id JohnMacFarlane.Pandoc # Check that it works pandoc --version
Pandoc picks the output format from the file extension after -o, so -o notes.docx makes a Word file and -o notes.html makes HTML.
Why I add -f gfm
By default, Pandoc reads its own dialect, Pandoc Markdown, which is stricter than what GitHub, VS Code, and AI chat tools produce (my cheat sheet has a short overview of Markdown flavors). The difference that bites most people: Pandoc Markdown needs a blank line before a list. Take this file, the way ChatGPT or Claude would write it:
Shopping list: - eggs - milk > [!NOTE] > Read this.
Here’s the HTML that pandoc ai.md -t html gave me. The list turned into one sentence, and the GitHub alert is just a quote:
<p>Shopping list: - eggs - milk</p> <blockquote> <p>[!NOTE] Read this.</p> </blockquote>
With -f gfm (GitHub Flavored Markdown), I got a real list and a note box:
<p>Shopping list:</p> <ul> <li>eggs</li> <li>milk</li> </ul> <div class="note"> <div class="title"> <p>Note</p> </div> <p>Read this.</p> </div>
In Pandoc 3.12.1, the GFM reader also handles tables, task lists, strikethrough, footnotes, $math$, emoji, and a YAML header with a title. So my rule: if the file was written for GitHub, VS Code, or by an AI tool, add -f gfm. If you write specifically for Pandoc and want its extras (raw LaTeX like \newpage, attributes on images, citations), leave it off.
Markdown to HTML
Without options, Pandoc writes an HTML fragment: just the body, no <html> or <head>. That’s what you want to paste into a CMS. For a page you can open and share, add -s (standalone):
# Fragment (body only) pandoc report.md -f gfm -o report.html # Complete page with a readable default style pandoc report.md -f gfm -s -o report.html # Set the browser-tab title without adding a visible title pandoc report.md -f gfm -s --metadata pagetitle="Quarterly report" -o report.html
The standalone page comes with a small built-in stylesheet (a 36em-wide column, readable fonts, styled tables). If there’s no title, Pandoc uses the file name for the <title>. A title: in a YAML header, like below, sets the tab title and adds a title block at the top of the page:
--- title: Quarterly report author: Erik date: October 2026 --- # Summary Sales grew **12%** this quarter.
Your own CSS, in one self-contained file
Use --css to link your own stylesheet. Note that this replaces Pandoc’s page styling: in my test, the 36em column and the fonts were gone, and only a few functional rules (for code and task lists) remained. A minimal stylesheet to start from:
body { max-width: 40em; margin: 2em auto; font-family: system-ui, sans-serif; }
table { border-collapse: collapse; }
th, td { border: 1px solid #ccc; padding: .3em .6em; }
A linked CSS file and images are separate files, so the page breaks when you email just the HTML. --embed-resources fixes that by putting everything inside the HTML file:
pandoc report.md -f gfm -s --css style.css --embed-resources -o report.html
I checked the result: the CSS was inlined in a <style> block, the image became a data:image/png;base64 URI, and the file had no links to anything local. (You’ll see --self-contained in older tutorials; it’s now a deprecated synonym for --embed-resources --standalone.)
Table of contents, code highlighting, and math
--tocadds a linked table of contents at the top (a<nav id="TOC">).- Fenced code blocks with a language get syntax highlighting automatically. Pick a theme with
--syntax-highlighting=tango(others: pygments, espresso, zenburn, kate, monochrome, breezedark, haddock). The old--highlight-stylestill works, but Pandoc 3.12 warns:Deprecated: --highlight-style. Use --syntax-highlighting instead. - Math like
$E = mc^2$comes out as plain italic text by default. Add--mathjaxand Pandoc loads MathJax from a CDN to typeset it properly in the browser.
Markdown to Word (.docx)
pandoc report.md -f gfm -o report.docx
This is where Pandoc really shines, because it produces a proper Word document, not text with formatting slapped on. In my test file, I found:
- Headings with Word’s own Heading 1 and Heading 2 styles, so the navigation pane and Word’s table of contents work.
- A real Word table, real Word footnotes, working hyperlinks, and the image embedded in the file.
- Math as a native, editable Word equation.
- Code blocks with syntax colors, and task lists as ☒ and ☐ bullets.
Use your own Word styles with –reference-doc
The default look is plain. To get your company font, colors, margins, or header and footer, give Pandoc a reference document. It ignores the reference document’s text and copies its styles and page setup. Make one from Pandoc’s own default, so all the style names match:
# 1. Get a copy of Pandoc's default reference document pandoc -o custom-reference.docx --print-default-data-file reference.docx # 2. Open custom-reference.docx in Word or LibreOffice, change the styles, save # 3. Convert with it pandoc report.md -f gfm --reference-doc=custom-reference.docx -o report.docx
In step 2, modify the styles (Home > Styles > right-click a style > Modify in Word) rather than formatting the text in the file. The ones that matter most are Normal, Body Text, First Paragraph, Heading 1 to 3, Title, Table, and Source Code; the full list is under --reference-doc in the Pandoc manual. To test it, I changed the Heading 1 color in a reference document to red: every Heading 1 in the converted file came out red, while the rest kept Pandoc’s defaults.
A table of contents in Word
--toc inserts a Word table-of-contents field. Pandoc can’t calculate page numbers, so the field starts out empty (in LibreOffice I saw only the “Table of Contents” heading). In Word, right-click the spot and choose Update Field; in LibreOffice, use Tools > Update > Update All.
Two more Word tips. For LibreOffice’s own format, just use -o report.odt; --reference-doc works for ODT too. And for a page break inside a Word document, you need a small raw Word XML block, which I explain in page breaks when exporting to PDF or Word.
Markdown to PDF
Pandoc doesn’t make PDFs itself. It converts your Markdown to an intermediate format (LaTeX, Typst, or HTML) and hands that to a separate PDF engine. The default is LaTeX, which most computers don’t have, so the first attempt usually ends like this:
$ pandoc report.md -o report.pdf 'pdflatex' not found. Please select a different --pdf-engine or install 'pdflatex'
You have two fixes: install LaTeX, or pick another engine with --pdf-engine. I tried three on the same test file (headings, a table, code, a task list, a footnote, math, an image, and a Mermaid block):
| Engine | What you install | Look | Time in my test | Style it with |
|---|---|---|---|---|
Typst (--pdf-engine=typst) | One program (43 MB on my Mac) | Clean, modern; footnotes at the page bottom | 0.3 s | YAML variables (paper, margins, font) |
LaTeX (the default, pdflatex, or xelatex, lualatex, tectonic) | A TeX distribution (a full MacTeX is about 4 GB; smaller ones exist) | Classic academic; best for math | 1.4 s (Tectonic) | Variables like geometry, mainfont; LaTeX templates |
WeasyPrint (--pdf-engine=weasyprint) | A Python program plus the Pango library | Like a printed web page; A4 by default | 1.0 s | CSS, including @page |

My pick for most people is Typst: one small download, no configuration, and a good-looking result. Use LaTeX if you have lots of math or need a journal template. Use WeasyPrint if you already think in CSS. You’ll also see wkhtmltopdf in older tutorials; its GitHub repository is archived, so I’d skip it.
Typst
Install Typst with brew install typst (macOS) or winget install --id Typst.Typst (Windows), then:
pandoc report.md -f gfm --pdf-engine=typst -o report.pdf # A4 paper instead of US Letter pandoc report.md -f gfm --pdf-engine=typst -V papersize=a4 -o report.pdf
For margins and fonts, put the settings in the YAML header of your file. The margin is a set of values (x, y, top, bottom, left, right), and in my test -V margin.x=2cm on the command line had no effect, while this worked:
--- title: Quarterly report papersize: a4 margin: x: 2cm y: 2.5cm mainfont: Helvetica fontsize: 11pt ---
The other Typst variables (page numbering, columns, line spacing, link colors) are listed under “Variables for Typst” in the Pandoc manual. Two things I ran into:
- Page breaks:
\newpageis LaTeX, and Pandoc silently dropped it in the Typst output (one page instead of two). Use a raw Typst block instead. With-f gfm, also add theraw_attributeextension (-f gfm+raw_attribute), or the block shows up as code:
Page one
```{=typst}
#pagebreak()
```
Page two
- Missing characters: Typst’s default font had the ☒ for a checked task but not the ☐ for an open one, which showed up as a box with a question mark. If you use task lists or unusual symbols, set a
mainfontthat has them.
LaTeX
LaTeX is Pandoc’s default and the most configurable engine. The catch is the install. Pandoc’s install page points out that a full MacTeX uses about four gigabytes and recommends the smaller BasicTeX or TinyTeX on a Mac, MiKTeX on Windows, and TeX Live from your package manager on Linux. I used Tectonic instead: a single program that downloads the LaTeX packages it needs on the first run. That first run took about two minutes and fetched 45 MB; after that, a PDF took a second and a half.
# Default engine (pdflatex), A4 with 2 cm margins pandoc report.md -V geometry:margin=2cm -V papersize=a4 -o report.pdf # xelatex, lualatex (and Tectonic) let you use any installed font pandoc report.md --pdf-engine=xelatex -V mainfont="Helvetica" -o report.pdf # Tectonic pandoc report.md --pdf-engine=tectonic -o report.pdf
With the default margins, the LaTeX PDF had the wide margins you know from academic papers; -V geometry:margin=2cm fixes that. For a page break, put \newpage on its own line. That works with Pandoc’s default Markdown, but not with -f gfm, which escapes it (see my page break tests).
WeasyPrint: style your PDF with CSS
With WeasyPrint, Pandoc makes HTML first, and WeasyPrint lays it out as pages. Everything is styled with CSS, including the paper size and margins:
/* print.css */
@page { size: A4; margin: 2cm; }
body { font-family: Georgia, serif; }
pandoc report.md -f gfm --pdf-engine=weasyprint --css print.css -o report.pdf
Expect a few harmless WARNING: Ignored ... lines about CSS properties WeasyPrint doesn’t support; the PDF is fine. On my Mac, the version installed with pip first failed with OSError: cannot load library 'libgobject-2.0-0', because it couldn’t find the Pango libraries. On macOS, brew install weasyprint avoids that; the WeasyPrint install guide covers Windows and Linux. One thing I didn’t like: task lists came out as large checkbox form fields with the text on the next line, so style ul.task-list yourself if you use them.
Or skip the PDF engine: print the HTML
If you have Chrome or Edge, you already have a good PDF engine. Make a self-contained HTML file with Pandoc and print it from the browser, or from the command line with headless Chrome. This worked for me on macOS (on Windows, use the full path to chrome.exe or msedge.exe):
pandoc report.md -f gfm -s --embed-resources -o report.html "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" --headless \ --no-pdf-header-footer --print-to-pdf=report.pdf report.html
Diagrams, math, and images in exports
Mermaid diagrams
GitHub draws Mermaid code blocks as diagrams, but Pandoc doesn’t: in HTML, Word, and every PDF engine I tried, the diagram came out as its source code. The cleanest fix is to turn the diagrams into images first with the official Mermaid CLI. It can process a whole Markdown file: it renders each mermaid block to an image and writes a new Markdown file that links to those images.
# Render the diagrams as PNG and write report-out.md npx -p @mermaid-js/mermaid-cli mmdc -i report.md -o report-out.md -e png # Convert the result as usual pandoc report-out.md -f gfm --pdf-engine=typst -o report.pdf
Use -e png for PDFs. With the default SVG output, Typst warned image contains foreign object, and the boxes in my diagram were there but the labels were missing, because Mermaid puts its text in HTML inside the SVG. The PNG version was fine, in the PDF and in Word.
For HTML output, you can let the browser draw the diagrams instead. Pandoc writes Mermaid blocks as <pre class="mermaid">, which is exactly what Mermaid’s JavaScript looks for. Save this as mermaid.html:
<script type="module">
import mermaid from "https://cdn.jsdelivr.net/npm/mermaid@12/dist/mermaid.esm.min.mjs";
mermaid.initialize({ startOnLoad: true });
</script>
pandoc report.md -f gfm -s --include-in-header=mermaid.html -o report.html
When I loaded that page in Chrome, the diagram was rendered as an SVG. It needs an internet connection to load Mermaid, though.
Math
Math is easier. $...$ and $$...$$ become editable equations in Word, properly typeset formulas with LaTeX and Typst, and need --mathjax in HTML (and in WeasyPrint, which showed plain text).
Images
Pandoc looks for images relative to the folder you run it from, not the folder the Markdown file is in. When I converted a file from another folder, I got this, and the image was replaced by its alt text:
[WARNING] Could not fetch resource logo.png: replacing image with description
Run Pandoc from the file’s folder, or tell it where to look with --resource-path=path/to/folder. More on image syntax and sizing in my Markdown images guide.
Markdown to PowerPoint and EPUB
Pandoc does slides and e-books too. For PowerPoint, each top-level heading becomes a slide, and a ::: notes block becomes speaker notes:
--- title: Q3 review author: Erik --- # Results - Sales grew **12%** - Two new markets # Next steps 1. Hire 2. Launch ::: notes Mention the budget. :::
pandoc slides.md -o slides.pptx gave me three slides: a title slide, “Results”, and “Next steps”, with the note attached to the last one. Like Word, PowerPoint output takes --reference-doc for your template (get Pandoc’s default with --print-default-data-file reference.pptx). The note syntax is Pandoc Markdown, so leave off -f gfm here.
For an e-book, pandoc book.md -o book.epub creates an EPUB with a title page, a table of contents, and your images inside. Give it a title in the YAML header; without one, my test EPUB’s table of contents was labeled “UNTITLED”. --epub-cover-image=cover.png adds a cover.
Batch conversion and automation
Once your options grow, put them in a defaults file instead of retyping them. This word.yaml holds everything for Word output:
from: gfm to: docx reference-doc: custom-reference.docx
Then convert every .md file in a folder with a loop (macOS, Linux, or Git Bash on Windows):
for f in *.md; do
pandoc -d word.yaml "$f" -o "${f%.md}.docx"
done
${f%.md} strips the .md, so notes.md becomes notes.docx. Make a pdf.yaml with pdf-engine: typst and the same loop gives you PDFs. The VS Code extension has its own shortcut for this: with "markdown-pdf.convertOnSave": true, it re-exports every time you save.
Converting Markdown to HTML in your own code
If you’re building a website or app, use a Markdown library instead of calling Pandoc. In JavaScript, the two big ones are markdown-it (the parser behind VS Code’s preview) and marked. After npm install markdown-it, this converts a file:
// convert.mjs
import { readFileSync, writeFileSync } from "node:fs";
import MarkdownIt from "markdown-it";
const md = new MarkdownIt();
const html = md.render(readFileSync("notes.md", "utf8"));
writeFileSync("notes.html", html);
With markdown-it 15.0.3, a heading, bold text, a link, and a table came out as you’d expect (tables are on by default). Like Pandoc without -s, it gives you an HTML fragment to put inside your own page template.
One difference matters for security. My test file also had a <script> tag. markdown-it escaped it, because raw HTML is off unless you pass html: true. marked 18.1.1 passed it through unchanged. So if the Markdown comes from your users, either use markdown-it’s default or run the HTML through a sanitizer such as DOMPurify. For quick jobs, both have a command-line tool: npx markdown-it notes.md > notes.html or npx marked -i notes.md -o notes.html. And if your site runs on WordPress, my WordPress Markdown guide covers the plugins and the block editor.
FAQ
How do I convert Markdown to PDF without installing anything?
Paste it into Google Docs with “Paste from Markdown” and download it as PDF, or open a rendered version (GitHub, an editor’s preview, an HTML export) in your browser and print it to PDF. Online converters work too, but don’t upload anything confidential.
Why does Pandoc say “pdflatex not found”?
Pandoc needs a separate program to make PDFs and uses LaTeX by default. Either install a LaTeX distribution or add --pdf-engine=typst (after installing Typst) or --pdf-engine=weasyprint.
How do I change the margins of a Pandoc PDF?
It depends on the engine. With LaTeX: -V geometry:margin=2cm. With Typst: a margin: entry with x and y in the YAML header. With WeasyPrint: @page { margin: 2cm; } in a CSS file passed with --css.
How do I make my Word export use my company template?
Create a reference document with pandoc -o custom-reference.docx --print-default-data-file reference.docx, change its styles (fonts, colors, headings, margins, header and footer) in Word, and convert with --reference-doc=custom-reference.docx. Copying styles from your existing template into that file works better than using the template directly, because Pandoc needs its own style names.
Why are my Mermaid diagrams missing from the PDF or Word file?
Pandoc doesn’t run Mermaid, so it outputs the diagram’s source code. Render the diagrams first with mmdc -i input.md -o output.md -e png and convert the output file, or use the VS Code Markdown PDF extension, which renders Mermaid itself.
Can I convert Word or PDF back to Markdown?
For Word, yes: pandoc report.docx -t gfm --extract-media=media -o report.md gave me clean headings, bold text, links, and tables, with the images saved in a folder. My code block came back as an indented block without its language, so expect some cleanup. PDFs are much harder, because a PDF doesn’t know what’s a heading or a table; Pandoc can’t read them at all.