skillfed

xhtml2pdf

PDF generator using HTML and CSS

xhtml2pdf v0.2.17 4.3M downloads/30d#2,326 on PyPI2,389
Permissive license Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for… (full text in the JSON record) AGING released

What it is and what it does

xhtml2pdf is a pure-Python HTML-to-PDF converter that wraps reportlab, html5lib, and pypdf to turn HTML5 and CSS 2.1 markup into PDF documents. It lets developers who know HTML and CSS generate PDF templates without learning a specialized PDF library or adopting a different technology stack. The tool is platform-independent and installs as a standard Python package.

The package handles the full pipeline: parsing HTML5 with html5lib, applying CSS styling, rendering text and images via reportlab (which requires a system graphics backend like cairo), and assembling the final PDF. It also integrates pyHanko for PDF signing, python-bidi for right-to-left text, arabic-reshaper for Arabic script support, and svglib for SVG embedding, making it suitable for multilingual and complex document layouts.

Use it for:

  • Generate invoice or receipt PDFs from web templates without duplicating design logic between HTML and PDF systems.
  • Build report generators that accept HTML input and produce downloadable PDF files for distribution.
  • Create multilingual PDF documents with proper text directionality and script handling for Arabic and bidirectional content.
  • Embed SVG graphics and images in PDF output while maintaining CSS styling from the source HTML.
  • Automate PDF certificate or document generation in web applications by reusing existing HTML/CSS templates.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Converts HTML and CSS to PDF documents using Python, enabling developers with web skills to generate PDF templates without learning specialized PDF libraries.

Yes, if you need to convert HTML/CSS to PDF and want to avoid learning a specialized PDF library. The permissive Apache 2.0 license and low install friction make it accessible. However, the aging maintenance status (last release 537 days ago) warrants caution in production: verify that its rendering quality and feature set meet your specific layout and CSS requirements before committing to it as a core dependency. No known security vulnerabilities as of the fact sheet date.

Install

xhtml2pdf on PyPI

pip

pip install xhtml2pdf

uv

uv add xhtml2pdf

poetry

poetry add xhtml2pdf

Installing xhtml2pdf

Before you install

Low friction install with a pure-Python wheel. Maintenance is aging—last release was 537 days ago and the last commit was 2026-01-19—but the repository remains active and not archived. The project carries 9 runtime dependencies including reportlab, html5lib, and pypdf, which are themselves mature libraries.

License in practice

Licensed under Apache License 2.0 (permissive). You may use, modify, and distribute xhtml2pdf and derivative works freely, provided you include a copy of the license and document any changes. No restrictions on commercial use.

Quickstart

pip install xhtml2pdf

from xhtml2pdf import pisa
from io import BytesIO

html_string = '<html><body><h1>Hello</h1></body></html>'
pdf_file = BytesIO()
pisa.CreatePDF(html_string, pdf_file)
pdf_file.seek(0)

Requires Python 3.8+. For bitmap and vector rendering, reportlab needs a system-level graphics backend; cairo (installed via OS package manager) is recommended, or legacy RenderPM can be used as an alternative.

Verify before relying

  • Whether the aging maintenance status (537 days since release) affects stability or security in production use cases.
  • How well CSS 3 features beyond CSS 2.1 are actually supported in practice.
  • Performance characteristics when rendering large or complex HTML documents.

Package facts

License Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for… (full text in the JSON record) (permissive)
Python support supports the current Python release (>=3.8)
Install friction low — pure-Python wheel
Runtime dependencies 9 — arabic-reshaper, html5lib, Pillow, pyHanko, pyhanko-certvalidator, pypdf, python-bidi, reportlab, svglib
Maintenance aging — 537 days since the last release
Last repo commit
First released
Downloads 4,345,363/month — #2,326 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: xhtml2pdf-0.2.17-py3-none-any.whl

Keywords: PDF, HTML, HTML, XML, CSS

Development Status :: 4 - BetaEnvironment :: ConsoleEnvironment :: Other EnvironmentIntended Audience :: DevelopersIntended Audience :: System AdministratorsLicense :: OSI Approved :: Apache Software LicenseNatural Language :: EnglishOperating System :: OS IndependentProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Topic :: DocumentationTopic :: MultimediaTopic :: Office/BusinessTopic :: PrintingTopic :: Text ProcessingTopic :: Text Processing :: FiltersTopic :: Text Processing :: FontsTopic :: Text Processing :: GeneralTopic :: Text Processing :: IndexingTopic :: Text Processing :: MarkupTopic :: Text Processing :: Markup :: HTMLTopic :: Text Processing :: Markup :: XMLTopic :: Utilities

Tags

html to pdf conversiongenerate pdf from htmlcss to pdf renderingpython pdf generatorhtml css pdf exportweb template to pdfreportlab html wrapper
pdf-generationhtml-renderingdocument-automation

More Utilities packages