Skip to content

Instantly share code, notes, and snippets.

@ammaaim
Last active April 18, 2017 10:36
Show Gist options
  • Save ammaaim/c5d60d7c4411ff33913d to your computer and use it in GitHub Desktop.
Save ammaaim/c5d60d7c4411ff33913d to your computer and use it in GitHub Desktop.
Python3 HTML to PDF generator
>>> INSTALL
pip3.4 install weasyprint
>>> EXAMPLE
from weasyprint import HTML, CSS
html_src='''
<h1>The title</h1>
<p>Content goes here
'''
css_src='@page { size: A4; margin: 1cm }'
HTML(string=html_src).write_pdf('weasyprint-website.pdf', stylesheets=[CSS(string=css_src)])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment