[web2py] Re: Forcing download of generated PDF
I put the output of the pdf generation tool into a StringIO object which is request.body the output never touches the filesystem. (web2py's request.body is an StringIO object) This controller will run in the background and download the document. The headers below are what you need in your controller for it to work the way you want. response.headers['Content-Type']="application/pdf" response.headers['Pragma']="private" response.headers['Cache-Control']="private, must-revalidate" response.headers['Content-disposition'] = 'attachment; filename=your_doc.pdf' return request.body.getvalue() On Wednesday, October 29, 2014 10:13:39 AM UTC-7, Jason Solack wrote: > > Hello everyone, i'm generating a PDF using pdfkit and i'd like my function > to force the download of the pdf file i'm making. > > Here's some simple code demonstrating the PDF being made in memory: > > def make_pdf(): > import pdfkit > pdf = pdfkit.from_string("test", False) > return pdf > > > Ideally i would like to have an "export" button on my page and have that > function called and then download the PDF i have made. > > Thank you in advance! > > Jason > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: Forcing download of generated PDF
With: return response.stream(open(path, 'rb')) You need save your file first, using tempfile maybe. On Wednesday, October 29, 2014 12:13:39 PM UTC-5, Jason Solack wrote: > > Hello everyone, i'm generating a PDF using pdfkit and i'd like my function > to force the download of the pdf file i'm making. > > Here's some simple code demonstrating the PDF being made in memory: > > def make_pdf(): > import pdfkit > pdf = pdfkit.from_string("test", False) > return pdf > > > Ideally i would like to have an "export" button on my page and have that > function called and then download the PDF i have made. > > Thank you in advance! > > Jason > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.