Generating and Downloading PDF
I have a system running Zope generating .pdf using the reportlabs lib. How can I put this files available to download? Because I'm attaching the file to a e-mail and sending a message to the user. I don't want to waste the time between the send and the arrival of the mail message. Thanks in advance. Fernando Lujan
Fernando Lujan wrote:
I have a system running Zope generating .pdf using the reportlabs lib.
How can I put this files available to download?
Because I'm attaching the file to a e-mail and sending a message to the user. I don't want to waste the time between the send and the arrival of the mail message.
Thanks in advance.
Fernando Lujan
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
I quote from an answer to a similar question on the german speaking usergroup R = self.REQUEST.RESPONSE R.setHeader('content-type', 'application/rtf') R.setHeader('content-length', str(len(data)) R.write(data) robert
robert wrote:
Fernando Lujan wrote:
I have a system running Zope generating .pdf using the reportlabs lib.
How can I put this files available to download?
Because I'm attaching the file to a e-mail and sending a message to the user. I don't want to waste the time between the send and the arrival of the mail message.
Thanks in advance.
Fernando Lujan
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
I quote from an answer to a similar question on the german speaking usergroup
R = self.REQUEST.RESPONSE R.setHeader('content-type', 'application/rtf') R.setHeader('content-length', str(len(data)) R.write(data) robert
Fernando, I did this with external python script using smtplib,MimeWriter, base64 and ReportLab modules: a) Create the pdf (unless it was aquired via self) using ReportLab b) Loop thru recipients and 1) format each email using MimeWriter 2) send it using smtplib.SMTP.sendmail( .... ) David
On Sat, Feb 26, 2005 at 12:14:11AM +0100, robert wrote:
R = self.REQUEST.RESPONSE R.setHeader('content-type', 'application/rtf') R.setHeader('content-length', str(len(data)) R.write(data)
That's great if you're serving PDFs that you can easily fit in RAM and throw away after the request. e.g something customized for each viewer. Or, if the PDFs are likely to be large, and you can reuse them, and you have space on the filesystem for them, and you want the fastest possible data stream Zope can deliver to the client while minimizing RAM usage, you could do something like (for zope later than 2.7.2 or so, I forget exactly which version): # untested! # doesn't provide cleanup of files! from ZPublisher.Iterators import filestream_iterator response = self.REQUEST.RESPONSE if not file_i_want_to_serve_exists: # ... write the file somewhere. # Bonus points if you can figure out how to start streaming it # while you're still writing it, but that may be # non-trivial. # Once the file's written, hand it off to the publisher # for efficient streaming. response.setHeader('content-type', 'application/pdf') response.setHeader('content-length', the_length) response.setBody(filestream_iterator(filename)) -- Paul Winkler http://www.slinkp.com
On Fri, 2005-02-25 at 21:24, Paul Winkler wrote:
On Sat, Feb 26, 2005 at 12:14:11AM +0100, robert wrote:
R = self.REQUEST.RESPONSE R.setHeader('content-type', 'application/rtf') R.setHeader('content-length', str(len(data)) R.write(data)
That's great if you're serving PDFs that you can easily fit in RAM and throw away after the request. e.g something customized for each viewer.
Or, if the PDFs are likely to be large, and you can reuse them, and you have space on the filesystem for them, and you want the fastest possible data stream Zope can deliver to the client while minimizing RAM usage, you could do something like (for zope later than 2.7.2 or so, I forget exactly which version):
# untested! # doesn't provide cleanup of files!
from ZPublisher.Iterators import filestream_iterator response = self.REQUEST.RESPONSE if not file_i_want_to_serve_exists: # ... write the file somewhere. # Bonus points if you can figure out how to start streaming it # while you're still writing it, but that may be # non-trivial.
# Once the file's written, hand it off to the publisher # for efficient streaming. response.setHeader('content-type', 'application/pdf') response.setHeader('content-length', the_length) response.setBody(filestream_iterator(filename))
Actuall, it's not "response.setBody" in the last line, it's just "return filestream_iterator(filename)". - C
participants (5)
-
Chris McDonough -
David Hassalevris -
Fernando Lujan -
Paul Winkler -
robert