This repository contains a simple script that converts Markdown and CSS into PDF documents. The heavy lifting is done by Python-Markdown, a tool for generating HTML from Markdown, and WeasyPrint, a tool for generating PDF documents from HTML and CSS. With this script, my CV in Markdown is converted into a PDF document.
- Install pyenv, a tool for managing Python versions.
- The file
.python-version
in the root folder specifies the Python version required by the conversion script. Navigate to the root folder and executepyenv install
to install this Python version. - Install
cairo
,pango
, andgdk-pixbuf
. On macOS, these tools can be installed withbrew
. - Install pipenv by executing
pip install pipenv
. There's an issue related to language and region settings that you might run into on Macs, but it's easy to resolve. - Create a new virtual environment with all dependencies by executing
pipenv install --dev --ignore-pipfile
. The flagignore-pipfile
is used to indicate that the exact versions of the dependencies as specified inPipfile.lock
should be installed. The flagdev
is used to also install development dependencies.
Before executing any of the commands below, you need to activate the virtual environment.
You can do so by executing pipenv shell
.
Your command prompt should now indicate that you've activated the virtual environment.
It can be deactivated by executing exit
.
The examples
folder contains a CV and a quotation.
- Execute
python md2pdf.py convert examples/cv.md examples/cv.css
to generate a PDF version of the CV. - Execute
python md2pdf.py convert examples/quotation.md examples/quotation.css
to generate a PDF version of the quotation.
When writing or designing documents, you can use python md2pdf.py watch <document_name>.md <stylesheet_name>.css
.
This will watch the given files and generate new output when they change.
Both an HTML document and a PDF document are generated.
The HTML document is generated because it's convenient to be able to play around with the CSS in a browser.
If you want to design your own documents, take a look at designing for print with CSS by Rachel Andrew.