Last active
August 29, 2015 13:55
-
-
Save molszewski/8689640 to your computer and use it in GitHub Desktop.
WeasyPrint + Jinja2 spike
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!venv/bin/python | |
# Script requires: | |
# - virtualenv in venv dir (virtualenv venv) | |
# - XQuartz-2.7.5 (MacOSX only, installed separately from https://xquartz.macosforge.org/landing/) | |
# - cairo pango gdk-pixbuf libxmllibxslt libffi (brew install cairo pango gdk-pixbuf libxmllibxslt libffi) | |
# - WeasyPrint (pip install WeasyPrint) | |
# - Jinja2 (pip install Jinja2) | |
from weasyprint import HTML | |
from jinja2 import Environment, FileSystemLoader | |
# load template | |
env = Environment(loader=FileSystemLoader('.')) | |
template = env.get_template('template.html') | |
# render template | |
rendered = template.render(messages=['Hello','World']) | |
# write to PDF | |
HTML(string=rendered).write_pdf('weasyprint_jinja2_spike_output.pdf') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment