Registry / data / markdown-pdf

markdown-pdf

JSON →
library1.13.2pypypi✓ verified 85d ago

markdown-pdf is a Python library designed to convert Markdown documents into PDF files. It utilizes `markdown-it-py` for efficient Markdown to HTML conversion and `PyMuPDF` for robust HTML to PDF rendering. Currently at version 1.13.1, the library is actively maintained with several releases per year, continuously adding new features and improvements.

pip install markdown-pdf
INSTALL
IMPORT
SIG · MARKDOWN-PDF
M
markdown-pdf
datapythonv1.13.2
Install
3.9s avg
Import
2186ms
Disk
83MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.13.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 84.3MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 3.9s · import 2.186s · 84MB
83MB installed
● package 83MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

MarkdownPdf
from markdown_pdf import MarkdownPdf
Section
from markdown_pdf import Section

This quickstart demonstrates how to create a multi-section PDF from Markdown strings. It shows initializing `MarkdownPdf` with options like `toc_level` and `optimize`, adding individual `Section` objects with custom settings (like disabling TOC for a section or applying `user_css`), and finally setting document metadata before saving the PDF to a file.

from markdown_pdf import MarkdownPdf, Section import os # Create a PDF with a Table of Contents (up to level 2 headings) and optimized output pdf = MarkdownPdf(toc_level=2, optimize=True) # Add the first section. The 'toc=False' ensures its title is not in the TOC. pdf.add_section(Section("# Document Overview\n\nThis is an introduction to the document.", toc=False)) # Add a second section with external and internal hyperlinks text_with_links = """ # Hyperlink Section - [External Link to GitHub](https://github.com/vb64/markdown-pdf) - [Internal Link to Subsection](#introduction-to-python) ## Introduction to Python Python is a versatile programming language. """ pdf.add_section(Section(text_with_links)) # Add a third section with custom CSS applied to its headings text_with_css = """ # Custom Styled Header This section demonstrates custom CSS to center its main heading. """ pdf.add_section(Section(text_with_css, user_css="h1 {text-align:center; font-size: 2em;}")) # Set PDF document metadata pdf.meta["title"] = "Markdown-pdf Example Guide" pdf.meta["author"] = "AI Assistant" # Define the output file name output_filename = os.environ.get('PDF_OUTPUT_FILE', 'example_document.pdf') # Save the generated PDF to a file pdf.save(output_filename) print(f"PDF '{output_filename}' generated successfully.")
markdown-pdf --version
Debug
Known issues
breakingThe project's license changed from MIT to AGPL-3.0 starting with version 1.6. Users of versions 1.6 and newer must review and comply with the AGPL-3.0 license terms.
fix
Assess the impact of the AGPL-3.0 license on your project's usage, distribution, and overall licensing strategy.
affects: >=1.6
gotchaThe core PDF generation relies on `PyMuPDF`, which is licensed under AGPL-3.0. This underlying dependency means that projects linking with or distributing `markdown-pdf` are generally subject to the copyleft provisions of the AGPL-3.0 license.
fix
Familiarize yourself with the AGPL-3.0 license to understand its implications for your software's distribution and source code availability.
affects: All versions
gotchaWhen embedding images, relative paths are resolved using the `root` parameter of the `Section` class (defaults to current working directory). Incorrect `root` settings can cause images to be missing in the output PDF.
fix
Explicitly set the `root` parameter in `Section(markdown_content, root='path/to/image_assets')` to the base directory containing your image files.
affects: All versions
gotchaBy default, each `Section` added to a `MarkdownPdf` instance will start on a new page. This is the intended behavior for logical document structuring but can be a 'gotcha' if you expect continuous flow.
fix
To have content flow continuously on a single page, combine all desired Markdown content into a single `Section` object.
affects: All versions
gotchaRendering PlantUML and Mermaid diagrams requires enabling specific plugins (`plantuml_plugin`, `mermaid_plugin`) when initializing `MarkdownPdf`; they are not active by default.
fix
Consult the `markdown-pdf` documentation to understand how to enable and configure these plugins for diagram rendering.
affects: PlantUML: >=1.11, Mermaid: >=1.12
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'markdown_pdf'
The 'markdown-pdf' library is not installed in your current Python environment or is not accessible on the Python path.
fix
Install the library using pip: `pip install markdown-pdf`
markdown-pdf image not showing in PDF
The image file specified in the Markdown could not be found or accessed by the 'markdown-pdf' library during conversion, often due to an incorrect path or missing file.
fix
Ensure the image file exists and its path in the Markdown is correct relative to the 'root' directory specified when creating a `Section` (default is current working directory). For example: `pdf.add_section(Section(markdown_text, root='./path/to/images'))`.
markdown-pdf Mermaid diagram not rendering
Mermaid or PlantUML diagrams fail to render in the output PDF, usually due to incorrect diagram syntax, issues with the configured external rendering server (if applicable for plugins), or the plugin not being correctly set up.
fix
Verify the Mermaid/PlantUML syntax is valid, ensure any external diagram rendering servers (if used by a plugin) are accessible and configured correctly, and confirm the relevant plugin is enabled and properly configured in your `MarkdownPdf` instance.
markdown-pdf custom font not applied
Custom fonts specified in the `user_css` are not found by PyMuPDF, or the font files are not accessible in the rendering environment.
fix
Ensure the custom font files are available in a directory accessible to the application (e.g., in the 'root' directory or a path specified in CSS's `@font-face` rule) and correctly referenced in the `user_css` provided to the `Section`.
Upgrade
Version history
1.13.2latest on PyPI · released May 28, 2026
Audit
Dependencies
markdown-it-pyrequiredUsed for converting Markdown syntax to HTML.
PyMuPDFrequiredUsed for rendering HTML content into PDF format.
requestsrequiredA dependency explicitly fixed in a recent release, likely for handling external resources.
Agent activity
2 hits · last 30 days
node
2
Resources
markdown-pdf — pip install markdown-pdf · libregistry