Convert Markdown files to PDF with styles.
The easiest way to go is to use pip:
$ pip install md2pdf
Nota bene: ensure, Weasyprint is fully functional before using md2pdf. You will find installation instructions in the project documentation: https://doc.courtbouillon.org/weasyprint/stable/first_steps.html#installation
Usage: md2pdf [OPTIONS] MD PDF
md2pdf command line tool.
Options:
--css PATH
-e, --extras TEXT
--version Show the version and exit.
--help Show this message and exit.
For example, try to generate the project documentation with:
$ md2pdf README.md README.pdf
Optionally, you may load an external style:
$ md2pdf --css tests/assets/input.css README.md README.pdf
And/or activate markdown extras:
$ md2pdf --css pygments.css -e fenced-code-blocks README.md README.pdf
You can use md2pdf
in your python code, like:
from md2pdf.core import md2pdf
md2pdf(pdf,
md=None,
raw=None,
css=None,
base_url=None,
extras=[],
)
Function arguments:
pdf
: output PDF file pathraw
: input markdown raw string contentmd
: input markdown file pathcss
: input styles path (CSS)base_url
: absolute base path for markdown linked content (as images)extras
: markdown extras that should be activatedInstall Docker
Pull the image:
$ docker pull jmaupetit/md2pdf
Now run your image:
$ docker run --rm \
-v $PWD:/app \
-u "$(id -u):$(id -g)" \
jmaupetit/md2pdf --css styles.css INPUT.MD OUTPUT.PDF
Clone this project first:
$ git clone git@github.com:jmaupetit/md2pdf.git
Install md2pdf along with its dependencies (using Poetry):
$ cd md2pdf
$ poetry install
To run the test suite with your active python version (virtual environment):
$ poetry run pytest
Lint the code via:
$ poetry run ruff md2pdf
Upload a new release to PyPI:
$ poetry build
$ poetry publish
If you are familiar with GNU Make, we also automate daily tasks using this lovely tool:
$ make help
md2pdf
is released under the MIT License. See the bundled LICENSE file for
details.