[Zope] pdf + external methods question

Dieter Maurer dieter@handshake.de
Tue, 8 Jan 2002 23:09:38 +0100


Garry Steedman writes:
 > after _much_ wailing and gnashing of teeth, i am now
 > happily churning out PDF reports via reportlab/
 > external methods, but i still have one irritation: i
 > am using a tempfile.mktemp(suffix=".pdf") object to
 > chuck the pdf into but am having trouble responsing
 > this back to the browser cleanly.
 > 
 > i am using this code (thx, messrs Washington +
 > Penny!):
 > 
 > c.save()
 > self.REQUEST.RESPONSE.setHeader('Content-type',
 > 'application/x-pdf')     
 > self.REQUEST.RESPONSE.write(open(mypdffile).read())
 > 
 > but the tempfile object seems to get mangled somewhere
 > in the process and the client doesn't recognise the
 > file as PDF because the PDF suffix gets lost
 > somewhere... any help most welcome...
Is it possible that your tempfile has not yet been closed
after writing?

  It is not a good idea to write to a file and then open
  it for reading without an intervening "close" (because
  part of the "written" data may still wait in internal buffers
  to be flushed to disk).


Dieter