-
-
Save Yemsheng/7fa998ee319cdc4db67aaa8b10a1d9ba to your computer and use it in GitHub Desktop.
Generating PDF using Flask & ReportLab
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
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