This is a typical Python library and is installed using pip

pip install xhtml2pdf


Python 3.8+

All mandatory requirements are listed in the pyproject.toml file and are installed automatically using the pip install xhtml2pdf method.

As PDF library we depend on reportlab, which needs a rendering backend to generate bitmaps and vector graphic formats. For more information about this, have a look at the reportlab docs.

The recommended choice is the cairo graphics library which has to be installed system-wide e.g. via the OS package manager in combination with the PyCairo extra dependency:

pip install xhtml2pdf[pycairo]

Alternatively, the legacy RenderPM can be used by installing:

pip install xhtml2pdf[renderpm]

Development environment

  1. If you don’t have it, install pip, the python package installer

    sudo easy_install pip

    For more information about pip refer to

  2. We recommend using venv for development. It is great to have a separate environment for each project, keeping the dependencies for multiple projects separated.

    For more information about venv refer to

  3. Create a virtual environment for the project. This can be inside the project directory, but cannot be under version control

    python -m venv .venv
  4. Activate your virtual environment

    source .venv/bin/activate

    Later to deactivate use

  5. Run tests to check your configuration

    python -m unittest discover tests

    You should have a log with success status:

    Ran 108 tests in 1.372s