[Image-SIG] Images in Zope/ReportLab
Fredrik Lundh
fredrik@pythonware.com
Wed, 9 May 2001 10:34:42 +0200
Heiner de Wendt wrote:> Here's an example code:
>
> *
> def page1(self,c,my1,my2):
> c.setFont("Times-Roman",8)
> c.setFillColorRGB(0.1,0.1,0.1)
> c.drawString(60,775,my1)
> c.drawString(60,750,my2)
> c.drawInlineImage(my2,60,500,width=100,height=80)
>
> def get(self):
> import PIL.Image
> from reportlab.pdfgen import canvas
> c = canvas.Canvas("/opt/zope/2-3-0/pdffiles/pdf1.pdf")
> my1=str(self.image1.id)
> my2=str(self.image1)
> page1(self,c,my1,my2)
> c.showPage()
> c.save()
> *
>
> I've tried various things in the "drawInlineImage" line, even
> directly giving the image name ('image1'), but ReportLab doesn't find
> it.
>
> The strings my1 and my2 give the following results:
> my1 (which is self.image1.id) : <Python Method Object at 8b785f0>
> my2 (which is self.image1): <img src="[complete URL here]/image1"
> alt=".." height="80" width="100" border="0"/>
looks like you're a bit too optimistic: ReportLab's drawInlineImage
method expects a *filename* or a PIL Image object, not a string
containing "<img src='...'>"...
try passing in the filename you used to create self.image1.
(or use PIL.Image.open(filename) to create a PIL object, and pass
that one to drawInlineImage)
Cheers /F