Registry / data / md2pdf

md2pdf

JSON →
library3.1.1pypypi✓ verified 85d ago

md2pdf is a Python library and CLI tool for converting Markdown files to PDF, offering features like custom styling, Jinja templating, and support for various Markdown extensions. It is currently at version 3.1.1 and is actively maintained, receiving regular updates for new features, bug fixes, and security enhancements.

pip install md2pdf
INSTALL
IMPORT
SIG · MD2PDF
M
md2pdf
datapythonv3.1.1
Install
6.4s avg
Import
Disk
98MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v3.1.1 · 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 · 97.3MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 6.4s · import 0.000s · 108MB
98MB installed
● package 98MB
Code
Verified usage

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

md2pdf
from md2pdf.core import md2pdf

This quickstart demonstrates how to use the `md2pdf` function from the core API to convert a Markdown string directly into a PDF file. You can specify Markdown content, output destination, optional CSS for styling, and desired Markdown extensions.

from md2pdf.core import md2pdf import os markdown_content = """ # My Awesome Document Hello, **md2pdf**! This is an example of converting Markdown to PDF using the library's API. - Item 1 - Item 2 ```python print("Code blocks are also supported") ``` """ output_filename = "my_document.pdf" try: md2pdf( md_content=markdown_content, dest=output_filename, css_file=None, # Path to a CSS file for custom styling, or None base_url=None, # Base URL for relative paths in markdown md_extensions=['extra', 'fenced_code', 'tables'] # Common Markdown extensions ) print(f"Successfully created PDF: {output_filename}") except Exception as e: print(f"Error converting markdown to PDF: {e}") # For WeasyPrint related errors, check system dependencies (see 'Problems')
md2pdf --version
Debug
Known issues
breakingThe command-line interface (CLI) underwent a significant breaking change in `v3.0.0`. It switched to Typer and moved from positional arguments to exclusively using options.
fix
Review the updated CLI usage by running `md2pdf --help`. For example, `md2pdf --input README.md --output README.pdf` replaces `md2pdf README.md README.pdf`.
affects: >=3.0.0
breaking`md2pdf` dropped support for Python versions older than 3.10 starting from `v2.0.0`. Attempts to install or run on older Python interpreters will fail.
fix
Ensure your Python environment is 3.10 or newer. Upgrade Python or use a virtual environment with a compatible version.
affects: >=2.0.0
gotchaRunning the `md2pdf` command-line tool requires installing the `cli` extra (`pip install "md2pdf[cli]"`). A basic `pip install md2pdf` will only install the library API, not the executable CLI.
fix
If you intend to use the `md2pdf` command in your terminal, always install with `pip install "md2pdf[cli]"`.
affects: >=3.0.0
gotchaSince `v2.0.0`, all input Markdown content is automatically treated as a Jinja2 template. This means any Jinja-like syntax (e.g., `{{ variable }}` or `{% for item in list %}`) will be processed, potentially leading to errors or unexpected output if not intended.
fix
If you don't use Jinja templating, ensure your Markdown content does not contain Jinja-like syntax that could conflict with templating rules. Pass a `jinja_template=None` if you are using the API and want to disable Jinja processing for some reason (though `md2pdf` processes `md_content` as a template directly).
affects: >=2.0.0
Errors
Common errors & fixes
md2pdf: command not found
The `md2pdf` CLI executable was not installed because the `cli` extra was omitted during installation.
fix
Install `md2pdf` with the CLI extras: `pip install "md2pdf[cli]`.
ModuleNotFoundError: No module named 'md2pdf'
The `md2pdf` library is not installed in the active Python environment, or the environment is not correctly activated.
fix
Install the library using pip: `pip install md2pdf` (or `pip install "md2pdf[cli]` for CLI).
md2pdf: error: unrecognized arguments: README.md output.pdf
This error typically occurs when using pre-v3.0.0 CLI syntax (positional arguments) on `md2pdf` versions 3.0.0 or later, where the CLI switched to Typer and uses only options.
fix
Update your CLI command to use options: `md2pdf --input README.md --output output.pdf`.
md2pdf.exceptions.ConversionError: WeasyPrint exited with error code 1. Make sure all external dependencies are installed. More info: https://doc.weasyprint.org/en/stable/install.html
WeasyPrint, a core dependency of md2pdf, relies on external system libraries like Pango, Cairo, and GDK-Pixbuf. These need to be installed at the operating system level.
fix
Install the necessary system dependencies for WeasyPrint. For Debian/Ubuntu: `sudo apt-get install python3-dev libffi-dev libxml2-dev libxslt1-dev libjpeg-dev libpng-dev zlib1g-dev libpango1.0-0 libcairo2 libgdk-pixbuf2.0-0`. For macOS: `brew install pango cairo gdk-pixbuf`.
Upgrade
Version history
3.1.1latest on PyPI · released Mar 31, 2026
Audit
Dependencies
clioptionalProvides command-line interface functionality (e.g., Typer, watchdog).
latexoptionalProvides extra dependencies for LaTeX specific processing (less common).
Agent activity
2 hits · last 30 days
node
2
Resources
md2pdf — pip install md2pdf · libregistry