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

Brower Jason Jason.Brower at kone.com
Fri Oct 2 05:39:26 EDT 2009


Don't worry about web2py. Unless you want to use a cool web framework. :D
I can return the object as a streamable item. And the web2py part is working properly.
But I don't think I am doing the pdf generation properly.
Here are the important bits...

def create_report():
from reportlab.pdfgen.canvas import Canvas
from reportlab.lib.pagesizes import A4, landscape
from reportlab.lib.units import cm, mm, pica
from reportlab.platypus import Paragraph, SimpleDocTemplate, Spacer
from reportlab.lib.styles import getSampleStyleSheet
from reportlab.graphics.shapes import Drawing
from reportlab.graphics.charts.barcharts import VerticalBarChart
import StringIO
output = StringIO.StringIO()
#My programming bits...
pdf.showPage()
pdf.save()
return response.stream(output,chunk_size=64*1024)

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.
Regards,
Jason Brower


-----Original Message-----
From: reportlab-users-bounces at lists2.reportlab.com [mailto:reportlab-users-bounces at lists2.reportlab.com] On Behalf Of Andy Robinson
Sent: 02/10/2009 11:04
To: For users of Reportlab open source software
Subject: Re: [reportlab-users] Return a file object rather than save afile...

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

> After a look through the main documentation I found section 2.2 and it

> shoulds how to open a file like object and insert a pdf into that.  But I

> would like to have just the file object itself to return as a downloadable

> stream. (I am using web2py)


I am not familiar with web2py, but if there is some kind of file-like
response object you can write to, then pass that to the Canvas
constructor. Alternatively, create a StringIO object (which is
file-like) and use that.

Best Regards,

Andy Robinson
_______________________________________________
reportlab-users mailing list
reportlab-users at lists2.reportlab.com
http://two.pairlist.net/mailman/listinfo/reportlab-users


More information about the reportlab-users mailing list