markdown-pdf
Markdown to pdf renderer
What it is and what it does
markdown-pdf is a Python library that transforms markdown text into PDF documents. It uses markdown-it-py to parse markdown into HTML and PyMuPDF to render that HTML as PDF. The package handles UTF-8 text in any language, embeds images referenced in markdown, generates a table of contents from headings, supports custom CSS styling, and allows multiple page sizes within a single document. It also provides a plugin system for rendering code blocks like plantuml diagrams into images.
The typical workflow is to create a MarkdownPdf instance, add one or more Section objects containing markdown text, optionally configure CSS and metadata, and then save to a file or bytes buffer. Each section starts on a new page, and you can control which heading levels appear in the table of contents. The package is designed for programmatic PDF generation from markdown content rather than as a command-line tool, though the description includes an example CLI script.
Use it for:
- Generate user guides or technical documentation from markdown source files with automatic table of contents and consistent styling.
- Create multi-section reports where each section can have different page sizes, margins, or styling rules.
- Embed images and diagrams (via plantuml plugin) directly into PDFs generated from markdown templates.
- Batch-convert markdown files to PDFs with custom branding via CSS and document metadata.
- Build documentation pipelines that render markdown to PDF with internal cross-references and clickable hyperlinks.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Converts markdown text to PDF files, with support for tables, images, hyperlinks, table of contents, custom CSS styling, and optional diagram rendering via plugins.
Yes, if you need to generate PDFs from markdown programmatically and can accept the AGPL-3.0-only license. The package is actively maintained, has low install friction, carries no known vulnerabilities, and offers a straightforward API with useful features like TOC generation, image embedding, and plugin support. The AGPL license is the main constraint: verify it aligns with your project's licensing model before committing.
Install
markdown-pdf on PyPI
pip
pip install markdown-pdfuv
uv add markdown-pdfpoetry
poetry add markdown-pdfInstalling markdown-pdf
Before you install
Low install friction with a pure Python wheel. Actively maintained as of 2026-05-28 with 154 repository stars. Five runtime dependencies (PyMuPDF, markdown-it-py, requests, plantuml, six) are all established packages.
License in practice
Licensed under AGPL-3.0-only. This copyleft license requires that any derivative work or modification must also be released under AGPL-3.0-only and that source code be made available to users. Consider this constraint if you plan to integrate it into proprietary or differently-licensed software.
Quickstart
pip install markdown-pdf
from markdown_pdf import MarkdownPdf, Section
pdf = MarkdownPdf(toc_level=2)
pdf.add_section(Section("# Title\n\nContent here"))
pdf.save("output.pdf")
Requires Python 3.8 or later. PyMuPDF may require system libraries; see PyMuPDF documentation for platform-specific setup.
Verify before relying
- Whether plantuml and mermaid diagram rendering requires external services or local installations beyond what the package provides.
- Performance characteristics and file size limits for large markdown documents or many embedded images.
- Exact CSS subset supported for styling; whether all standard CSS properties work as expected.
Package facts
| License | AGPL-3.0-only (agpl) |
| Python support | supports the current Python release (>=3.8) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 5 — PyMuPDF, markdown-it-py, requests, plantuml, six |
| Maintenance | actively maintained — 78 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 557,003/month — #6,016 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: markdown_pdf-1.13.2-py3-none-any.whl
Tags
More Markup packages
PyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
markdown-it-pyA Python markdown parser that converts markdown…
permissive · top 100 on PyPI
beautifulsoup4Beautiful Soup parses HTML and XML documents…
permissive · top 100 on PyPI
et-xmlfileet_xmlfile writes large XML files with minimal…
permissive · top 1,000 on PyPI
tomlkitParses and edits TOML files while preserving…
permissive · top 1,000 on PyPI
docstring-parserParses Python docstrings in ReST, Google,…
permissive · top 1,000 on PyPI
md2pdfConverts Markdown files to PDF with custom CSS…
permissive · top 15,000 on PyPI
mdutilsmdutils generates Markdown files…
permissive · top 5,000 on PyPI
pdfkitPython wrapper for wkhtmltopdf that converts…
permissive · top 5,000 on PyPI
weasyprintWeasyPrint converts HTML and CSS into PDF…
permissive · top 1,000 on PyPI
gh-md-to-htmlConverts GitHub-flavored Markdown to HTML with…
unclear · top 15,000 on PyPI
mistuneMistune converts Markdown text to HTML using a…
permissive · top 1,000 on PyPI
markdown-to-confluenceConverts Markdown files to Confluence Storage…
permissive · top 5,000 on PyPI
plantuml-markdownA Markdown extension that converts PlantUML…
permissive · top 5,000 on PyPI
mkdocs-with-pdfGenerates a single PDF file from an MkDocs…
permissive · top 15,000 on PyPI
xhtml2pdfConverts HTML and CSS to PDF documents using…
permissive · top 5,000 on PyPI