0

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).

KetZoomer
  • 2,701
  • 3
  • 15
  • 43
decoy24601
  • 39
  • 1
  • 4
  • 1
    Does 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 Answers1

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)

From: https://stackoverflow.com/a/34438445/13710015

KetZoomer
  • 2,701
  • 3
  • 15
  • 43