How to Convert Markdown to PDF: 4 Methods
September 15, 2026 · 7 min read
How to Convert Markdown to PDF: 4 Free Methods
Converting markdown to PDF turns your plain text documents into polished, shareable files with preserved formatting. You can do it with our free online tool, Pandoc on the command line, a VS Code extension, or a Python script. This tutorial covers each method step by step so you can pick the one that fits your workflow.
Why Convert Markdown to PDF?
Markdown is great for writing, but PDF is the standard for sharing finished documents. PDFs preserve your formatting across every device and operating system. Common reasons to convert include sending reports to clients, submitting academic papers, creating invoices, generating documentation for offline use, and archiving finalized content.
The conversion process parses your markdown syntax (headings, bold, code blocks, tables, images) and renders it into a styled PDF page with fonts, margins, and page breaks. Different tools produce different visual results, so choosing the right converter matters.
Method 1: Convert Markdown to PDF Online (Free)
The fastest way to turn a markdown file into a PDF is our free online tool. No installation, no account required for basic use.
Step 1: Open the Markdown to PDF converter.
Step 2: Paste your markdown content into the editor on the left side. The live preview shows your formatted document in real time.
Step 3: Click the "Export PDF" button. Your browser downloads the PDF file.
The tool handles headings, bold, italic, code blocks with syntax highlighting, tables, images (from URLs), blockquotes, and lists. KaTeX math equations render correctly in the PDF output.
Try it directly in this page:
The free plan includes 3 tool operations per day, shared across the PDF, DOCX, HTML, URL, and formatter tools. Pro removes that cap.
Try free today
3 PDF exports/day, no sign-up required. Upgrade anytime for unlimited.
Method 2: Convert with Pandoc (Command Line)
Pandoc is the most powerful converter for technical users. It is a free, open-source tool that runs on Windows, macOS, and Linux.
Step 1: Install Pandoc from pandoc.org. You also need a LaTeX distribution (TeX Live on Linux, MacTeX on macOS, or MiKTeX on Windows) for PDF output.
Step 2: Run the conversion command:
pandoc input.md -o output.pdf
Step 3: Open output.pdf to verify the result.
Pandoc converts markdown through LaTeX, which produces publication-quality PDFs with proper typography. You can customize the output with templates and variables:
pandoc input.md -o output.pdf \
--pdf-engine=xelatex \
-V geometry:margin=1in \
-V fontsize=12pt \
-V mainfont="Inter"
Pandoc strengths: Handles complex documents with footnotes, citations (BibTeX), table of contents, numbered sections, and cross-references. Ideal for academic papers and technical documentation.
Pandoc limitations: Requires a LaTeX installation (hundreds of megabytes to several gigabytes, depending on the distribution), command-line usage, and configuration for custom styling. Not suitable for quick, one-off conversions.
Method 3: Convert with VS Code Extension
If you already use VS Code for markdown editing, the Markdown PDF extension converts files without leaving the editor.
Step 1: Install the "Markdown PDF" extension from the VS Code marketplace (by yzane).
Step 2: Open your .md file in VS Code.
Step 3: Right-click in the editor and select "Markdown PDF: Export (pdf)." The PDF generates in the same directory as your markdown file.
Customization options in VS Code settings:
{
"markdown-pdf.margin.top": "1.5cm",
"markdown-pdf.margin.bottom": "1.5cm",
"markdown-pdf.headerTemplate": "<span style='font-size: 9px;'>My Document</span>",
"markdown-pdf.footerTemplate": "<span style='font-size: 9px;'><span class='pageNumber'></span>/<span class='totalPages'></span></span>"
}
The extension uses a Chromium renderer, so the output matches how the document looks in a browser. It handles images, tables, code blocks, and Mermaid diagrams.
Method 4: Convert with Python
For automated or batch conversions, Python with the markdown and weasyprint libraries produces reliable PDFs:
import markdown
from weasyprint import HTML
# Read markdown file
with open("input.md", "r") as f:
md_content = f.read()
# Convert to HTML
html_content = markdown.markdown(md_content, extensions=["tables", "fenced_code"])
# Wrap in styled HTML
styled_html = f"""
<html>
<head><style>
body {{ font-family: sans-serif; max-width: 800px; margin: auto; padding: 40px; }}
code {{ background: #f5f5f5; padding: 2px 6px; border-radius: 3px; }}
pre {{ background: #f5f5f5; padding: 16px; border-radius: 8px; overflow-x: auto; }}
table {{ border-collapse: collapse; width: 100%; }}
th, td {{ border: 1px solid #ddd; padding: 8px; text-align: left; }}
</style></head>
<body>{html_content}</body>
</html>
"""
# Generate PDF
HTML(string=styled_html).write_pdf("output.pdf")
Install dependencies with:
pip install markdown weasyprint
This approach is ideal for CI/CD pipelines, batch processing, and automated report generation. You control every aspect of the styling through CSS.
Which Method Should You Choose?
| Use Case | Best Method | Why |
|---|---|---|
| Quick one-off conversion | Online tool | No setup, instant results |
| Academic papers with citations | Pandoc | BibTeX, footnotes, LaTeX quality |
| Daily editing workflow | VS Code extension | Integrated in your editor |
| Automated batch processing | Python script | Scriptable, CI/CD friendly |
| Mobile or shared computer | Online tool | Works in any browser |
For most users, the online converter handles the everyday cases. Switch to Pandoc when you need advanced features like citation management, custom LaTeX templates, or multi-format output.
Common Issues During Conversion
Images not appearing: Make sure image URLs are absolute (start with https://). Relative paths may not resolve during conversion. For local images, use Pandoc or VS Code which have access to your file system.
Tables breaking across pages: Most converters do not prevent page breaks inside table rows. Keep tables short (under 20 rows per table) or use Pandoc with the --variable=classoption:landscape flag for wide tables.
Code blocks losing syntax highlighting: Our online tool and VS Code preserve highlighting. Pandoc highlights code by default and lets you pick a theme with --highlight-style (e.g., --highlight-style=tango).
Math equations not rendering: Ensure your converter supports KaTeX or MathJax. Our online tool renders KaTeX. Pandoc handles LaTeX math natively.
Frequently Asked Questions
Summary
Turning markdown into a PDF is simple with the right tool. Our online converter handles quick conversions in seconds, and the editor gives you a live preview while you write. Pandoc produces publication-quality output for complex documents. VS Code integrates conversion into your editor, and Python scripts automate batch processing. Start with the embedded tool above to convert your first file, then explore the markdown cheat sheet for formatting your content before export.
Written by the Markdown Editor Online team. Last updated April 2026.