[reportlab-users] Return a file object rather than save afile...

Andy Robinson andy at reportlab.com
Fri Oct 2 07:43:37 EDT 2009

2009/10/2 Brower Jason <Jason.Brower at kone.com>:

> Somehow I need to make the save work with the output and I am am just to know with this file object stuff to know what to do.

Here's how to save your PDF as a string in memory.

buf = StringIO.StringIO()

c = Canvas(buf)

#do your drawing here

c.save() #PDF file is written into the buffer at this point

#extract contents as a byte string
rawPdfFileContent = buf.read()

You then pass this to the response. If it was Django, I could write
to the response object (which is file-like), so I could do this and
cut out the StringIO...

c = Canvas(response)


More information about the reportlab-users mailing list