[Zope] Generating and Downloading PDF
pw_lists at slinkp.com
Fri Feb 25 21:24:34 EST 2005
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))
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):
# 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
# Once the file's written, hand it off to the publisher
# for efficient streaming.
More information about the Zope