Why Convert to PDF?

Markdown is great, but the recipient may not have a viewer. Sending a .md file directly might mean they can't open it or see a bunch of symbols. PDF is a universally cross-platform format: any device displays it with consistent formatting, 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. Using mdview as an example:

  • Open the .md file with mdview and verify the rendered output;
  • In the preview window, right-click → Export PDF (or use the system's "Print → Save as PDF");
  • Choose the save location, done.

The entire process is done locally—no files are uploaded to any server, making it friendly for documents with sensitive content. Typora and other editors also offer "Export → PDF" functionality with similar principles.

Fastest path: After installing mdview, double-click .md to open → right-click to export PDF. Two steps done, no commands to remember.

Method 2: Online Conversion Tools

Search for "Markdown to PDF" in your browser to find many online conversion sites: upload or paste Markdown, download the generated PDF.

  • Pros: No installation, cross-platform;
  • Cons: You must upload content to third-party servers, not suitable for sensitive documents; local images may be lost; limited control over styling.

Method 3: Pandoc Command Line (Advanced)

For users comfortable with the command line, Pandoc is a powerful "Swiss army knife for document conversion." After installing Pandoc, a single command does the job:

pandoc document.md -o document.pdf

Note: Exporting PDF typically requires an additional LaTeX engine (like xelatex), which is relatively complex to configure. Suitable for batch conversion and automation scripts—regular users don't need to bother.

Method 4: VS Code Plugin

Install the Markdown PDF extension in VS Code to right-click and export PDF directly from the editor. Suitable for developers who already use VS Code for writing documents and don't want to switch tools.

Comparison of Four Methods

MethodDifficultyPrivacyLocal imagesStyle controlBest for
Viewer exportVery easyLocalYesMediumEveryone
Online conversionEasyUploadedNoLowOne-off, non-sensitive
PandocHigherLocalNeeds configHighAdvanced / batch
VS Code pluginMediumLocalYesMediumDevelopers

Formatting Tips Before Exporting to PDF

  • Use proper heading levels: Progress through #, ##, ### for a clear structure in the PDF;
  • Avoid overly wide tables: Super-wide tables get squeezed or truncated in PDF—simplify columns;
  • Control image width: Oversized images may break the page layout—crop appropriately;
  • Avoid overly long code blocks: Watch for page breaks in long code blocks to avoid splitting mid-block.

Summary

For 90% of people, "open in viewer → right-click to export PDF" is the optimal solution: simple, local, privacy-safe. Pandoc and plugins are advanced options for those with special needs.

About formatting: Different tools produce PDFs with different styles (fonts, margins, code highlighting). If appearance matters, preview with mdview first, then export for the most intuitive results.