Skip to content

Instantly share code, notes, and snippets.

@souzaux
Forked from widoyo/kas.py
Created July 21, 2016 20:07
Show Gist options
  • Select an option

  • Save souzaux/ccedf31eba30b600acfea5aef9621295 to your computer and use it in GitHub Desktop.

Select an option

Save souzaux/ccedf31eba30b600acfea5aef9621295 to your computer and use it in GitHub Desktop.
Generating PDF using Flask & ReportLab
from flask import make_response
from reportlab.pdfgen import canvas
# ...
@app.route('/pdf')
def pdf():
import cStringIO
output = cStringIO.StringIO()
p = canvas.Canvas(output)
p.drawString(100, 100, 'Hello')
p.showPage()
p.save()
pdf_out = output.getvalue()
output.close()
response = make_response(pdf_out)
response.headers['Content-Disposition'] = "attachment; filename='sakulaci.pdf"
response.mimetype = 'application/pdf'
return response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment