Skip to content

Instantly share code, notes, and snippets.

@dalanmiller
Created August 6, 2012 09:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dalanmiller/3272853 to your computer and use it in GitHub Desktop.
Save dalanmiller/3272853 to your computer and use it in GitHub Desktop.
How to use Pisa to create a pdf from html
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