-
-
Save souzaux/ccedf31eba30b600acfea5aef9621295 to your computer and use it in GitHub Desktop.
Generating PDF using Flask & ReportLab
This file contains hidden or 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