Skip to content

xhtml2pdf

1,983 18 115 Apache License 2.0
0.2.9 (30 Jan 2023) May 19 2011 542.7 thousand (month)

xhtml2pdf is a Python library that allows you to convert HTML and CSS documents to PDF files. It is built on top of ReportLab, a powerful PDF generation library for Python.

xhtml2pdf makes it easy to convert HTML and CSS documents to PDF by using ReportLab's powerful layout engine to handle the rendering of the document.

The library supports a wide variety of HTML and CSS features, including tables, lists, images, and links. It also supports several popular CSS frameworks such as Bootstrap and Foundation.

To use xhtml2pdf, you first need to install it via pip by running `pip install xhtml2pdf``. Once it is installed, you can use the xhtml2pdf.pisa.pisaDocument() function to convert an HTML file to a PDF.

Example Use


from xhtml2pdf import pisa

with open('input.html', 'r') as html_file:
    html = html_file.read()

with open('output.pdf', 'wb') as pdf_file:
    pisa.pisaDocument(html, pdf_file)

Alternatives / Similar


382 1.5.3 (1 year, 7 months ago) Feb 09 2022 compare
209 0.2.25 (7 months ago) Feb 09 2022 compare

Other Languages

1,693 4.0.0 (1 year, 11 months ago) Apr 18 2015 compare