Skip to content

Instantly share code, notes, and snippets.

@Yemsheng
Forked from widoyo/kas.py
Created May 26, 2016 09:28
Show Gist options
  • Save Yemsheng/7fa998ee319cdc4db67aaa8b10a1d9ba to your computer and use it in GitHub Desktop.
Save Yemsheng/7fa998ee319cdc4db67aaa8b10a1d9ba 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