Skip to content

Instantly share code, notes, and snippets.

@widoyo
Created October 16, 2012 07:42
Show Gist options
  • Select an option

  • Save widoyo/3897853 to your computer and use it in GitHub Desktop.

Select an option

Save widoyo/3897853 to your computer and use it in GitHub Desktop.

Revisions

  1. widoyo revised this gist Oct 16, 2012. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions kas.py
    Original file line number Diff line number Diff line change
    @@ -3,6 +3,7 @@

    # ...

    @app.route('/pdf')
    def pdf():
    import cStringIO
    output = cStringIO.StringIO()
  2. widoyo created this gist Oct 16, 2012.
    21 changes: 21 additions & 0 deletions kas.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    from flask import make_response
    from reportlab.pdfgen import canvas

    # ...

    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