[reportlab-users] drawImage does not accept PIL objects
Hervé Cauwelier
herve.cauwelier at free.fr
Tue Mar 23 05:08:46 EDT 2010
Hi,
I have the following program: http://bpaste.net/show/4621/
It simply "paste" an image on the center of a page, open a new page, and
so on.
According to the documentation, I can provide "drawImage" with PIL Image
objects. But when I try:
Traceback (most recent call last):
File "/home/herve/bin/cbz2pdf", line 65, in <module>
convert(filename, outname, options.resolution, delete=options.delete)
File "/home/herve/bin/cbz2pdf", line 33, in convert
canvas.drawImage(image, x, y, width=w, height=h)
File "/usr/lib/python2.6/site-packages/reportlab/pdfgen/canvas.py",
line 825, in drawImage
imgObj = pdfdoc.PDFImageXObject(name, image, mask=mask)
File "/usr/lib/python2.6/site-packages/reportlab/pdfbase/pdfdoc.py",
line 2076, in __init__
ext = string.lower(os.path.splitext(source)[1])
File "/usr/lib/python2.6/posixpath.py", line 95, in splitext
return genericpath._splitext(p, sep, altsep, extsep)
File "/usr/lib/python2.6/genericpath.py", line 91, in _splitext
sepIndex = p.rfind(sep)
File "/usr/lib/python2.6/site-packages/PIL/Image.py", line 512, in
__getattr__
raise AttributeError(name)
AttributeError: rfind
It treats the "image" argument as a filename, not an open image.
I have to use "drawInlineImage" instead that seems to produce a bigger
PDF than expected.
I run reportlab 2.4 on Archlinux x86_64.
Maybe there's a better recipe to convert a batch of images to PDF?
Thanks for your help,
Hervé Cauwelier
More information about the reportlab-users
mailing list