md2pdf
The Markdown to PDF conversion tool with styles
What it is and what it does
md2pdf is a Markdown-to-PDF converter that bridges markdown source files and styled PDF output. It accepts markdown input (from files or raw strings), applies optional CSS stylesheets, and renders the result as a PDF using weasyprint as its rendering engine. The tool supports Jinja2 templating within markdown, allowing dynamic content injection via frontmatter or programmatic context variables, and integrates markdown extensions from pymdown-extensions for features like syntax highlighting and emoji support.
You can use it as a command-line tool for one-off conversions or batch processing (with parallel workers), or embed it in Python code as a library function. It's designed for developers who need to generate styled PDF documentation from markdown sources—common in technical writing, report generation, and documentation pipelines. The package supports Python 3.10 through 3.14 and is actively maintained.
Use it for:
- Generate styled PDF documentation from markdown README files with custom CSS branding.
- Batch convert multiple markdown files to PDF with parallel processing using the --workers option.
- Create dynamic PDF reports by embedding Jinja2 templates and frontmatter variables in markdown source.
- Integrate markdown-to-PDF conversion into a Python application or documentation build pipeline.
- Render markdown with syntax-highlighted code blocks using pymdown-extensions and custom CSS.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Converts Markdown files to PDF with custom CSS styling, Jinja templating, and syntax highlighting support via a CLI tool or Python library.
Yes, if you need to convert markdown to styled PDFs. The package is actively maintained, has no known vulnerabilities, low install friction, and a permissive license. The main condition is ensuring weasyprint's system dependencies are available on your platform—check the weasyprint installation guide before installing. For markdown-to-PDF workflows, this is a solid, production-ready choice.
Install
md2pdf on PyPI
pip
pip install md2pdfuv
uv add md2pdfpoetry
poetry add md2pdfInstalling md2pdf
Before you install
Low friction: pure Python wheel with six runtime dependencies (jinja2, markdown, pygments, pymdown-extensions, python-frontmatter, weasyprint). Active maintenance with last commit 2026-08-14. Requires weasyprint to be fully functional on your system before use, per the documentation.
License in practice
MIT license (permissive) means you can use, modify, and distribute md2pdf freely in commercial and private projects with minimal restrictions.
Quickstart
pip install md2pdf[cli]
md2pdf -i README.md
Or as a library:
from md2pdf.core import md2pdf
md2pdf('output.pdf', md='input.md', css='style.css')
Weasyprint must be fully functional on your system; see https://doc.courtbouillon.org/weasyprint/stable/first_steps.html#installation for platform-specific setup.
Verify before relying
- Whether weasyprint's system dependencies (e.g., Cairo, Pango) are easily available on all target platforms or represent a common installation barrier.
- Performance characteristics when processing large markdown files or batch conversions with the --workers parameter.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 6 — jinja2, markdown, pygments, pymdown-extensions, python-frontmatter, weasyprint |
| Maintenance | actively maintained — 136 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 204,901/month — #9,597 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: md2pdf-3.1.1-py3-none-any.whl
Keywords: cli, css, html, markdown, pdf
Tags
More Utilities packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
charset-normalizerDetects and normalizes text encoding from…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
PygmentsPygments is a syntax highlighter that colorizes…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
markdown-pdfConverts markdown text to PDF files, with…
agpl · top 15,000 on PyPI
django-weasyprintProvides Django class-based views and response…
permissive · top 15,000 on PyPI
mdutilsmdutils generates Markdown files…
permissive · top 5,000 on PyPI
weasyprintWeasyPrint converts HTML and CSS into PDF…
permissive · top 1,000 on PyPI
xhtml2pdfConverts HTML and CSS to PDF documents using…
permissive · top 5,000 on PyPI
gh-md-to-htmlConverts GitHub-flavored Markdown to HTML with…
unclear · top 15,000 on PyPI
notion2mdExports Notion pages and blocks to Markdown…
permissive · top 15,000 on PyPI
pydyfpydyf generates PDF documents from Python code…
permissive · top 1,000 on PyPI
mkdocs-with-pdfGenerates a single PDF file from an MkDocs…
permissive · top 15,000 on PyPI
markdownifyConverts HTML to Markdown, with fine-grained…
permissive · top 1,000 on PyPI