[reportlab-users] Problems with drawImage()

Robin Becker robin at reportlab.com
Thu Feb 9 13:34:06 EST 2006


William Hudspeth wrote:
> 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=canvas.Canvas("test.pdf")
> c.drawImage("/var/www/html/tmp/select.png", 15, 150, width=200,
> height=100)
> c.showPage()
> c.save()
> 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",

this is odd it's not the same as your text above ie no leading '/'
> height="120")
>   File "/usr/local/lib/python2.4/site-
> packages/reportlab/pdfgen/canvas.py", line 572, in drawImage
> .......
>   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"

the above would be expected if the line actually reads
	crybaby.drawImage("var/www/html/tmp/select.png", 15,1

Another point to remember about cgi apps etc etc is that they usually run as 
another user eg www:www and so may not have the same access to the file system 
as the handomatic user.
-- 
Robin Becker


More information about the reportlab-users mailing list