Python client for HTML2PDF4Doc JavaScript library.
Actively maintained. Last release 4 days ago, commits in 9 of the last 26 weeks. A safe choice.
pip install html2pdf4dochtml2pdf4doc_python
html2pdf4doc_python is the Python wrapper/CLI for the html2pdf4doc JavaScript library that prints HTML pages into PDFs using Chrome/Chromedriver.
This repository focuses strictly on the Python-side automation layer. The rendering logic remains in the JS core.
Installation
-
Install Google Chrome (or Chrome for Testing) on the machine that will run the CLI.
-
Install the package from PyPI:
pip install html2pdf4doc
Python 3.8+ is required.
See also: the Ubuntu-based container Dockerfile and the GitHub CI files found
in the .github/workflows folder.
Usage
Download or reuse ChromeDriver with SSL verification enabled by default:
python -m html2pdf4doc.main get_driver
python -m html2pdf4doc.main print input.html output.pdf
Disable SSL (corporate environments)
Disable SSL certificate verification only when needed, for example in a restricted corporate environment with custom TLS interception:
python -m html2pdf4doc.main get_driver --disable-ssl-check
python -m html2pdf4doc.main print --disable-ssl-check input.html output.pdf
Pin a specific Chrome binary
Pin a specific Chrome/Chromium binary with --chrome-binary, for example to
use Chrome for Testing or a binary in a non-standard location. Without this
flag, html2pdf4doc auto-detects the Chrome/Chromium binary on the machine.
python -m html2pdf4doc.main get_driver --chrome-binary /path/to/chrome
python -m html2pdf4doc.main print --chrome-binary /path/to/chrome input.html output.pdf
Set the HTML2PDF4DOC_CHROME_BINARY environment variable instead of the
flag, for example in CI or Docker environments:
export HTML2PDF4DOC_CHROME_BINARY=/path/to/chrome
python -m html2pdf4doc.main print input.html output.pdf
html2pdf4doc resolves the Chrome binary in this order:
--chrome-binaryHTML2PDF4DOC_CHROME_BINARY- auto-detection.
Developer guide
Getting started
1. (Optional) Create and activate a virtual environment
python -m venv .venv && source .venv/bin/activate