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 md2pdfVerified import paths — ran on the pinned version, not inferred.
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.
Review the updated CLI usage by running `md2pdf --help`. For example, `md2pdf --input README.md --output README.pdf` replaces `md2pdf README.md README.pdf`.
Ensure your Python environment is 3.10 or newer. Upgrade Python or use a virtual environment with a compatible version.
If you intend to use the `md2pdf` command in your terminal, always install with `pip install "md2pdf[cli]"`.
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).
Install `md2pdf` with the CLI extras: `pip install "md2pdf[cli]`.
Install the library using pip: `pip install md2pdf` (or `pip install "md2pdf[cli]` for CLI).
Update your CLI command to use options: `md2pdf --input README.md --output output.pdf`.
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`.