[reportlab-users] StringIO() in a SimpleDocTemplate

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


Hi,



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)

canvas.draw()

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 :



doc=SimpleDocTemplate('doctemplate.pdf')

objects_to_draw = []

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

objects_to_draw.append(para)



img= platypus.Image(figure_to_string(fig))

objects_to_draw.append(img)





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?



Regards,



Nassim

-------------- 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