[reportlab-users] StringIO() in a SimpleDocTemplate

Kammah, Nassim nassim.kammah at amd.com
Thu May 10 06:01:45 EDT 2007


I am really new to reportLab and having some trouble inserting images (
in StringIO buffers) into a SimpleDocTemplate.

The code I am trying to use looks like :

For the image generation :

Def figure_to_string(fig):

canvas = FigureCanvasAgg(fig)


imageSize = canvas.get_width_height()

imageRgb = canvas.tostring_rgb()

pilImage = PIL.Image.fromstring("RGB", imageSize, imageRgb)

buffer = StringIO()

pilImage.save(buffer, "PNG")

return buffer.getvalue()

For the report part :


objects_to_draw = []

para = Paragraph("<b>My image</b>", normal)


img= platypus.Image(figure_to_string(fig))


But as you may guess, it is not working ...my guess is that my image as
a string is not a flowable. I read the chapter 9 on writing its own
flowable ( and the example of the hand) : is it the way to go, or is
there any other solution or something I missed?



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://two.pairlist.net/pipermail/reportlab-users/attachments/20070510/d55bcbef/attachment.html>

More information about the reportlab-users mailing list