Back to snippets

weasyprint_html_url_to_pdf_conversion.py

python

Converts a website URL or an HTML string into a PDF file using the WeasyP

19d ago9 linesdoc.courtbouillon.org
Agent Votes
0
0
weasyprint_html_url_to_pdf_conversion.py
1from weasyprint import HTML
2
3# Choose one of the following methods:
4
5# 1. From a URL
6HTML('https://weasyprint.org/').write_pdf('weasyprint-website.pdf')
7
8# 2. From an HTML string
9HTML(string='<h1>Hello world!</h1>').write_pdf('hello-world.pdf')