Created
August 6, 2012 09:41
-
-
Save dalanmiller/3272853 to your computer and use it in GitHub Desktop.
How to use Pisa to create a pdf from html
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
pdf_path = os.path.join(os.path.dirname(__name__),'static/CCT',pdf_name) | |
#RENDER CCT TEMPLATE AND THEN CONVERT INTO A PDF | |
#Path to CCT templates | |
template_path = os.path.join(current_dir, 'static/CCT') | |
#Settings jinja environment paths | |
jinja_env = Environment(loader=FileSystemLoader(template_path)) | |
#Convert rendered template with jinja into string = final cct template | |
cct_template = jinja_env.get_template(u'cct_template.html').render( | |
...fill in variables for template... | |
) | |
with open(pdf_path, 'wb') as doc: | |
pdf = pisa.CreatePDF(cct_template, doc) | |
if pdf.err: | |
flash('There was a problem creating the PDF file. Please try again, or contact somebody awesome.') | |
return redirect(url_for('make_mail')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment