Why convert to PDF?
Markdown is great, but the recipient might not have a viewer, and sending a raw .md file may result in unformatted text or a mess of symbols. PDF is universally compatible: any device opens it with the same layout, making it ideal for formal sharing, printing, and archiving.
Method 1: Export directly from a Markdown viewer (simplest)
This is the method most people should use. Take mdview as an example:
- Open the .md file in mdview and confirm the rendering;
- In the preview window, right-click → Export PDF (or use system "Print → Save as PDF");
- Choose a save location, done.
The whole process is done locally, files aren't uploaded to any server, which is great for sensitive content. Editors like Typora also offer "Export → PDF," with similar principles.
Fastest path: install mdview, double-click to open a .md file → right-click to export PDF. Two steps, no commands to remember.
Method 2: Online conversion tools
Search "Markdown to PDF" in your browser and you'll find many online converters: upload or paste Markdown, download the generated PDF.
- Pros: no installation, cross-platform;
- Cons: you have to upload content to a third-party server, which isn't suitable for sensitive documents; local images may be lost; conversion styling is uncontrollable.
Method 3: Pandoc command line (advanced)
For command-line users, Pandoc is a powerful "document conversion swiss army knife." Once installed, one command completes the conversion:
pandoc document.md -o document.pdf
Note: exporting PDF usually requires installing an additional LaTeX engine (such as xelatex), which is relatively complex. Good for batch conversion and automation scripts, but not worth the hassle for ordinary users.
Method 4: VS Code plugin
Install the Markdown PDF extension in VS Code to export PDF directly from the editor. Good for developers who already use VS Code to write documents and don't want to switch tools.
Comparison of the four methods
| Method | Difficulty | Privacy | Local images | Style control | Best for |
|---|---|---|---|---|---|
| Viewer export | Easiest | Local | ✓ | Medium | Everyone |
| Online conversion | Easy | Upload to third party | ✕ | Low | Temporary, non-sensitive |
| Pandoc | Higher | Local | Needs config | High | Advanced / batch |
| VS Code plugin | Medium | Local | ✓ | Medium | Developers |
Layout tips before exporting PDF
- Use proper heading levels: use
#,##,###hierarchically, and the PDF will have a clear structure; - Keep tables narrow: overly wide tables get squeezed or cut off in PDF, so reduce column count;
- Control image width: very large images may overflow the page, crop them appropriately;
- Watch long code blocks: long code blocks may split across pages awkwardly.
Summary
For 90% of people, "open in a viewer → right-click export PDF" is the best solution: simple, local, and privacy-safe. Pandoc and plugins are advanced options for users with special needs.
About layout: PDF styles vary by tool (fonts, margins, code highlighting). If appearance matters, preview in mdview first and then export — the result is most intuitive.