Reputation: 49
I am trying to figure out how to convert and download an html page to pdf with python on a headless ubuntu server. I have tried using wkhtmltopdf/pdfkit and none of the versions work that I have tried (including using a static version, rather than the ubuntu repository version since that has reduced functionality).
Upvotes: 1
Views: 1372
Reputation: 2914
You can use WeasyPrint
Install:
pip install weasyprint
Code:
import weasyprint
pdf = weasyprint.HTML('http://www.google.com').write_pdf()
open('google.pdf', 'wb').write(pdf)
From: https://stackoverflow.com/a/34438445/13710015
Upvotes: 1