You also can use pdfkit:

Usage

import pdfkit
pdfkit.from_url('http://google.com', 'out.pdf')

Install

MacOS: brew install Caskroom/cask/wkhtmltopdf

Debian/Ubuntu: apt-get install wkhtmltopdf

Windows: choco install wkhtmltopdf

See official documentation for MacOS/Ubuntu/other OS: https://github.com/JazzCore/python-pdfkit/wiki/Installing-wkhtmltopdf

Answer from NorthCat on Stack Overflow
๐ŸŒ
APITemplate.io
apitemplate.io โ€บ home โ€บ convert html to pdf in python with 5 popular libraries in 2026
Convert HTML to PDF in Python with 5 Popular Libraries in 2026 - APITemplate.io
3 days ago - Try our free HTML to PDF converter online today! In this article, we will look at 5 popular Python libraries for converting HTML to PDF: Playwright, WeasyPrint, xhtml2pdf, Pyppeteer, and python-pdfkit.
Discussions

HTML to PDF using Python and Headless Chrome
I just use weasyprint to transform HTML+CSS into PDF. Running headless Chrome seems slightly overkill for most applications, but it would make sense for dynamically rendered content I suppose. More on reddit.com
๐ŸŒ r/django
11
5
February 7, 2024
looking for an "low dependency" or pythonesque way to generate PDF's
Honestly all the good options I've found have required licenses, or are extremely low level, and a pain to use Eventually I always end up just outgrowing them and using a html -> pdf converter https://gotenberg.dev - this is what I use now, you can host your own and have all your clients use it via API calls (just post an html + CSS file and it returns a PDF) Alternatively just pop open a page in their default browser and have them print it to PDF More on reddit.com
๐ŸŒ r/Python
58
191
October 10, 2022
HTML to PDF
Look at dompdf-python-tools More on reddit.com
๐ŸŒ r/PythonLearning
9
1
September 26, 2024
HTML to PDF with performances
We moved away from HTML generated PDFs to use a layout engine on top of a 2D graphics API. Reason for us was that we needed to handle PDF documents of 6000-10000 pages. HTML generation was very demanding on memory and also slow. A document of 7000 pages takes us about 45 seconds to generate, including data fetching. The html one took several minutes and potentially ran into memory issues. We run all PDF generation outside the app in a docker container which is triggered by a message queue. It automatically scales out depending how many messages that is in queue. For this we use an Azure Container App. More on reddit.com
๐ŸŒ r/webdev
43
25
January 6, 2024
๐ŸŒ
PyPI
pypi.org โ€บ project โ€บ pyhtml2pdf
pyhtml2pdf ยท PyPI
Simple python wrapper to convert HTML to PDF with headless Chrome via selenium.
      ยป pip install pyhtml2pdf
    
Published ย  Dec 20, 2025
Version ย  0.1.0
๐ŸŒ
DocRaptor
docraptor.com โ€บ python-html-to-pdf
Compare Top Python HTML to PDF Libraries - Open-Source and Commercial
Our partnership with the Prince commercial PDF library means we have the best support for PDF-specific functionality, such as advanced headers and footers, footnotes, fine-tuned page-break controls, forms, accessible PDFs, printerโ€™s marks, varying page sizes, and much more. DocRaptor also has better CSS and JavaScript support than any non-Chromium-based open-source HTML-to-PDF library. Python-based WeasyPrint has more PDF-specific features than any other open-source library, regardless of language.
๐ŸŒ
GitHub
github.com โ€บ mikahama โ€บ pdfy
GitHub - mikahama/pdfy: A Python library for converting HTML files into PDF with Chrome's engine. ยท GitHub
options = {"paperWidth": 8.3, "paperHeight":11.7} p.html_to_pdf("html_file.htm", pdf_path="pdf_file.pdf" options=options)
Starred by 21 users
Forked by 7 users
Languages ย  Python
๐ŸŒ
Reddit
reddit.com โ€บ r/django โ€บ html to pdf using python and headless chrome
r/django on Reddit: HTML to PDF using Python and Headless Chrome
February 7, 2024 -

I often see questions pop up here and on Discord for how to convert an HTML page to PDF.

There are many ways of course, but I thought I'd share how I do it!

In this post I show how I use a simple Python utility function to start Chrome and output a PDF. For bonus points, I also cover some CSS tricks to control how content splits across pages, and how to prepare a Docker image that contains Chrome.

HTML to PDF Using Python and Headless Chrome

Anyone have a better/simpler way of handling it?

๐ŸŒ
PDFCrowd
pdfcrowd.com โ€บ api โ€บ html-to-pdf-python
HTML to PDF / Python Documentation
This page serves as a guide for using the PDFCrowd API to convert web pages and HTML content to PDF in Python applications.
Find elsewhere
๐ŸŒ
GitHub
github.com โ€บ xhtml2pdf โ€บ xhtml2pdf
GitHub - xhtml2pdf/xhtml2pdf: A library for converting HTML into PDFs using ReportLab ยท GitHub
xhtml2pdf is a HTML to PDF converter using Python, the ReportLab Toolkit, html5lib and pypdf. It supports HTML5 and CSS 2.1 (and some of CSS 3).
Starred by 2.4K users
Forked by 654 users
Languages ย  Python 52.5% | HTML 45.2% | CSS 2.1%
๐ŸŒ
The Python Code
thepythoncode.com โ€บ article โ€บ convert-html-to-pdf-in-python
How to Convert HTML to PDF in Python - The Python Code
Learn how you can convert HTML pages to PDF files from an HTML file, URL or even HTML content string using wkhtmltopdf tool and its pdfkit wrapper in Python.
๐ŸŒ
Nutrient
nutrient.io โ€บ blog โ€บ sdk โ€บ how to generate pdf reports from html in python
Python PDF generator: Convert HTML to PDF with WeasyPrint and Nutrient API
July 29, 2025 - Multi-platform โ€” Available on multiple operating systems, including Linux, Windows, and macOS. Python integration โ€” WeasyPrint is a Python-based tool, easily integrating with Python projects.
๐ŸŒ
IronPDF
ironpdf.com โ€บ ironpdf for python โ€บ blog โ€บ python pdf tools โ€บ html to pdf python
Convert HTML to PDF in Python (Developer Tutorial) | IronPDF for Python
January 19, 2026 - Each library offers unique features ... specific needs. PyHTML2PDF is an open-source Python library that converts your local HTML file into a professionally formatted PDF document in a matter of seconds....
๐ŸŒ
DocRaptor
docraptor.com โ€บ documentation โ€บ python
How to convert HTML-to-PDF with Python Documentation - DocRaptor HTML to PDF Converter
As the only API that uses the Prince PDF engine, DocRaptor uniquely supports advanced PDF generation features such as mixed layouts and header placements, accessible PDF tagging, crop marks, and more. We've been maintaining the DocRaptor Python package since 2016. Our library only supports Python 3 (we're proud members of the movement to drop Python 2 support). We've done our best to make the DocRaptor package the easiest way to convert HTML to PDF with Python.
๐ŸŒ
PyPDF
py-pdf.github.io โ€บ fpdf2 โ€บ HTML.html
fpdf2 - HTML
This is implemented by using html.parser.HTMLParser from the Python standard library. The whole HTML 5 specification is not supported, and neither is CSS, but bug reports & contributions are very welcome to improve this. cf. Supported HTML features below for details on its current limitations. For a more robust & feature-full HTML-to-PDF converter in Python, you may want to check Reportlab (or xhtml2pdf based on it), WeasyPrint or borb.
๐ŸŒ
Templated
templated.io โ€บ blog โ€บ how-to-convert-html-to-pdf-with-python
Convert HTML to PDF in Python with 5 Popular Libraries
February 21, 2024 - Hi, Iโ€™m Pedro, the founder of Templated, an API that automates images, PDFs, and videos. In this guide, Iโ€™m going to share five popular Python libraries for converting HTML to PDF.
๐ŸŒ
Nutrient
nutrient.io โ€บ blog โ€บ sdk โ€บ how to convert html to pdf using wkhtmltopdf and python
Python HTML to PDF: Convert HTML to PDF using wkhtmltopdf
August 13, 2024 - Install wkhtmltopdf on your system, and then use pdfkit to generate PDFs from URLs, HTML strings, or files with from_url(), from_string(), or from_file(). Customize output with options for page size, orientation, and margins.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-convert-html-pdf
Python Convert Html to PDF - GeeksforGeeks
December 30, 2017 - ... sudo apt-get install wkhtmltopdf For Windows: (a)Download link: WKHTMLTOPDF (b)Set: PATH variable set binary folder in Environment variables. Step3: Code in Python to Download: (i) Already Saved HTML page
๐ŸŒ
Apryse
docs.apryse.com โ€บ core โ€บ guides โ€บ features โ€บ conversion โ€บ convert-html โ€บ python
HTML to PDF Conversion Library in Python | Apryse documentation
The HTML2PDF converter supports HTML conversion from a string or URL and offers many options to control page size and formatting. Samples available in Python, C# (.Net), C++, Go, Java, Node.js (JavaScript), PHP, Ruby, VB.
๐ŸŒ
Pdfendpoint
pdfendpoint.com โ€บ python-html-to-pdf
Python Libraries for HTML to PDF Conversion
Free, Fast and Easy to setup HTML to PDF API for converting URL and HTML to pixel perfect PDFs. Sample implementations in Node.js, Python, C#, Java, etc.
๐ŸŒ
Edgeventures
edgeventures.com โ€บ kb โ€บ post โ€บ 2025 โ€บ 01 โ€บ 29 โ€บ convert-html-to-pdf-s-and-word-docs
Converting HTML to PDF in Python: A Comprehensive Guide
January 29, 2025 - from weasyprint import HTML def ... 'r') html_content = file.read() html_to_pdf(html_content, 'weasyprint.pdf') ... xhtml2pdf is a pure Python library that doesn't require external dependencies....
๐ŸŒ
Medium
medium.com โ€บ @pymupdf โ€บ how-to-convert-html-tables-to-pdf-5aead22683c8
How to Convert HTML Tables to PDF Using Python | Medium
May 10, 2024 - Use Python to Convert HTML tables to PDF. PyMuPDF now supports a large portion of HTML syntax that is used to define tables.