[Zope] PDF from external method

Jim Penny jpenny@universal-fasteners.com
Thu, 25 Oct 2001 11:12:50 -0400

On Thu, Oct 25, 2001 at 09:23:59AM -0400, Jim Washington wrote:
> Juergen R. Plasser / HEXAGON wrote:
> >Ok, sorry, this was a python script error.
> >
> >Another question: Reportlab examples create files, how can I "RESPONSE" 
> >them to Zope?
> What I am using:
> pdffile.seek(0)
> self.REQUEST.RESPONSE.setHeader("Content-type","application/pdf")
> self.REQUEST.RESPONSE.write(pdffile.read())
> -- Jim Washington

This is very nice.

Yet another way is to simply build a HTML file pointing to the
.pdf file generated.

def build_pdf(...):
   # omitted code builds pdf file in variable pdf_filename
   # referenced as pdf_url
   return "<a href="%s">%s</a>" % (pdf_url, pdf_filename)

  Allows .pdf to be served by static webserver
  Requires extra click to get to pdf.
  Requires a policy to reap stale pdf's
  Caching generated pdf's may (or may not) be a big win.  It depends
    on the nature of your task.  I suspect, psychobabblically speaking,
    that caching will occur more naturally to people who are treating
    pdf's as semi-static content by delivering a file name, than to 
    those who purely consider a pdf to be something to be delivered
    as a result of a method invocation.

Note:  The disadvantages may not be as large as you think.  Many
people are disconcerted by long load-times and/or sudden pop-up
windows.  This splits download/viewer startup time away from
data gathering/pdf generation time and will typically
be perceived as more responsive; despite stop watch time showing
that it is far slower due to the necessity of the extra click.  
(That is, people are often happier with 2 events of duration t/2 
than one event of duration t, especially if they have a chance to 
"walk away" in the middle.)  Thus, for many people, the extra click
may be perceived as an advantage!

The policy for reaping pdf's is actually neutral.  Note that Jim
Washington's method left the pdf file on the hard disk somewhere.
If you regard the external method as generating files rather than 
byte-streams, the need for a reaping process simply leaps out at you.

Jim Penny

> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists - 
> http://lists.zope.org/mailman/listinfo/zope-announce
> http://lists.zope.org/mailman/listinfo/zope-dev )