[Zope] PDF from external method

Chris Meyers chris@hddesign.com
Thu, 25 Oct 2001 08:47:26 -0500


On Thu, Oct 25, 2001 at 01:55:47PM +0200, 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?
> 
> Juergen
> 

One way that I do this is after the pdf file is created, I set up a function that opens and reads that file into a string and then return the string back to zope. You can then set up the MIME header of the zope object calling the reportlab script to be PDF which should open up the appropriate pdf viewer in your browser.

<Function to read pdf. This is an external method or a python script.>
def readPDF(pdf_file_name):
  BUFSIZE=2000
  pdf=''
  f=open(pdf_file_name)
  d=f.read(BUFSIZE)
  while d:
    pdf=pdf+d
    d=f.read(BUFSIZE)
  return pdf
</function>

<DTML_SCRIPT to call readPDF function>
Content-type: application/pdf

<dtml-var expr="readPDF(pdf_file_name)">

</DTML_SCRIPT>

HTH
Chris