[reportlab-users] Problems with drawImage()

William Hudspeth bhudspeth at edac.unm.edu
Thu Feb 9 10:19:10 EST 2006

I am having problems using drawImage() to insert an image (PNG) file
into my PDF when the function is embedded in a script. My script looks
like this:
print 'Content-type: text/html\n'
import sys
from reportlab.pdfgen import canvas

print "<html><head><title>PDF Generation</title></head><body>"
c.drawImage("/var/www/html/tmp/select.png", 15, 150, width=200,
print "</body></html>"


When I enter these commands at the Python prompt, the PDF file is
created exactly as I have specified. However, when I execute the
identical script, or I run it through a web browser, I get the following
error messages:


Content-type: text/html

<html><head><title>Fun with Stubby</title></head><body>
Traceback (most recent call last):
  File "./stub_pdf_builder.py", line 36, in ?
    crybaby.drawImage("var/www/html/tmp/select.png", 15,195, width="40",
  File "/usr/local/lib/python2.4/site-
packages/reportlab/pdfgen/canvas.py", line 572, in drawImage
    imgObj = pdfdoc.PDFImageXObject(name, image, mask=mask)
  File "/usr/local/lib/python2.4/site-
packages/reportlab/pdfbase/pdfdoc.py", line 1779, in __init__
  File "/usr/local/lib/python2.4/site-
packages/reportlab/pdfbase/pdfdoc.py", line 1785, in loadImageFromA85
    imagedata = map(string.strip,pdfutils.cacheImageFile
  File "/usr/local/lib/python2.4/site-
packages/reportlab/pdfbase/pdfutils.py", line 41, in cacheImageFile
    img = ImageReader(filename)
  File "/usr/local/lib/python2.4/site-packages/reportlab/lib/utils.py",
line 519, in __init__
    self.fp = open_for_read(fileName,'b')
  File "/usr/local/lib/python2.4/site-packages/reportlab/lib/utils.py",
line 457, in open_for_read
    raise IOError('Cannot open resource "%s"' % name)
IOError: Cannot open resource "var/www/html/tmp/select.png"


Any help would be greatly appreciated.


More information about the reportlab-users mailing list