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).
Asked
Active
Viewed 885 times
0
-
1Does this answer your question? [How to convert webpage into PDF by using Python](https://stackoverflow.com/questions/23359083/how-to-convert-webpage-into-pdf-by-using-python) – KetZoomer Jan 10 '21 at 22:52
1 Answers
1
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)

KetZoomer
- 2,701
- 3
- 15
- 43
-
-
@decoy24601 i think you just replace 'google.pdf' with whatever you want – KetZoomer Jan 11 '21 at 02:54