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 OverflowYou 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
WeasyPrint
pip install weasyprint # No longer supports Python 2.x.
python
>>> import weasyprint
>>> pdf = weasyprint.HTML('http://www.google.com').write_pdf()
>>> len(pdf)
92059
>>> open('google.pdf', 'wb').write(pdf)
HTML to PDF using Python and Headless Chrome
looking for an "low dependency" or pythonesque way to generate PDF's
HTML to PDF
HTML to PDF with performances
Videos
» pip install pyhtml2pdf
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?