decoy24601
decoy24601

Reputation: 49

How to Convert HTML Pages to Pdf in Ubuntu using Python?

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

Answers (1)

KetZoomer
KetZoomer

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

Related Questions