html2pdf
HTML to a single continuous PDF page. (中文说明)
html2pdf report.html
The PDF is one page as wide as you choose and exactly as tall as the content, so it reads the way the page scrolls in a browser. No paper-size breaks, no blank band at the bottom of every sheet, no card or table cut in half. Output is vector by default: text stays selectable and searchable, links stay clickable, and fonts are embedded.
Why not Save as PDF
A browser's print dialog always cuts the document into sheets. For anything laid out as a web page rather than a paper document, that leaves you choosing between white space and split content. Client-side libraries that turn the page into a canvas first produce images, so the text is gone.
html2pdf drives headless Chromium through Playwright and declares the page size with a CSS @page rule sized to the rendered content, with prefer_css_page_size set. Very tall pages render correctly this way; passing the size through the PDF API's width and height parameters did not in testing.
Install
uv tool install git+https://github.com/openwhale-labs/html2pdf
html2pdf --install-browser
pipx install git+https://github.com/openwhale-labs/html2pdf works the same way. The second command downloads the headless Chromium build matching the installed Playwright. Run it again after upgrading html2pdf if it reports that Chromium is missing.
Usage
html2pdf input.html [output.pdf]
html2pdf input.html --width 1200 # page width in CSS px (default 1000)
html2pdf input.html --hide ".lang-switch" # hide elements before rendering
html2pdf input.html --image # full-page screenshot, for pages with
# blur, backdrop-filter or soft gradients
html2pdf input.html --image --scale 3 # sharper screenshot (default 2)
html2pdf input.html --paged # multi-page output following the
# document's own @page and page-break rules
html2pdf input.html --open # open the PDF when done
The output path defaults to the input name with a .pdf extension. Elements with the class toolbar are hidden automatically, which is a common name for a fixed on-screen control bar that has no place in a document. --open uses the platform's default PDF viewer.
Screen styles are used, not print styles, and rendering waits for web fonts to load. The document must be self-contained: inline CSS, local images, or data URIs. To export a language or theme variant of a page that switches at runtime, write a copy of the HTML with the initial state set in the markup and convert that.
--paged is for documents that are designed as pages, such as slide decks with an @page { size: 1280px 720px } rule and explicit page breaks. It renders with print media and lets Chromium paginate. The layout viewport is 1280 px wide (or --width if larger) and 1400 px tall, so size slides in px rather than vw and vh. samples/slides.html is a three-slide example.
As a library
from html2pdf.cli import html_to_pdf
width, height = html_to_pdf("report.html", "report.pdf", width=1000)
Development
git clone https://github.com/openwhale-labs/html2pdf
cd html2pdf
uv tool install -e .
uv run --with pytest pytest
Rendering tests are skipped when Playwright's Chromium is not installed (html2pdf --install-browser). samples/sample.html is taller than any sheet of paper and exercises the fixed toolbar, tables, cards and a tall block; samples/slides.html covers --paged.
License
MIT. Copyright (c) 2026 OpenWhale Labs.
Release files for html2pdf-onepage 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| html2pdf_onepage-0.1.0.tar.gz | 11.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| html2pdf_onepage-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 18.9 kB
Release files / html2pdf_onepage-0.1.0.tar.gz
| Download URL | html2pdf_onepage-0.1.0.tar.gz |
|---|---|
| Size | 11.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0f8122fe930cc4969c7b0e781085e056d6daf3de7db545e98eaa35213158f0d6
|
|
BLAKE2b-256 checksum How to use checksums |
0b6b0c0ea752b13bcf9e10abf56b418c39f2fafee3e7e83c0cff733c5094f1f8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 5, 2026.
Transparency logRelease files / html2pdf_onepage-0.1.0-py3-none-any.whl
| Download URL | html2pdf_onepage-0.1.0-py3-none-any.whl |
|---|---|
| Size | 7.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e2a26b29725eaeaaaf2c39adb4df1975bf2c6d2bf08754783e1b044d03a2e58d
|
|
BLAKE2b-256 checksum How to use checksums |
1ef3199b72763ccd5c9ad4b3c763d87f2a22307d663212f8c29b908a46499894
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 5, 2026.
Transparency log