[reportlab-users] drawImage produces blank page only

Tim Roberts timr at probo.com
Thu Dec 29 13:30:42 EST 2005


On Thu, 29 Dec 2005 11:05:41 -0500 (EST), "Bernd Prager"
<bernd at prager.ws> wrote:

>I'm trying to convert an image to a pdf file.
>My test program is very simple:
>
>#!/usr/bin/python
>import sys, Image
>from reportlab.pdfgen import canvas
>
>def main():
>    im = Image.open('out300.jpg')
>    c = canvas.Canvas("pythonJpg.pdf")
>    c.pagesize = im.size
>    c.pageCompression = 1
>    c.verbosity = 0
>    c.drawImage('out300.jpg', 0, 0)
>    c.showPage()
>    c.save()
>
># main loop
>if __name__ == '__main__':
>    main()
>    sys.exit()
>
>Unfortunately the Adobe PDF reader (I tested version 6 and 7) only
>displays and prints an empty page from the generated document.
>  
>

These statements serve no purpose:
    c.pagesize = im.size
    c.pageCompression = 1
    c.verbosity = 0

Those are the names of parameters to the canvas.Canvas constructor. 
They are NOT names of attributes of the Canvas class.  All you are doing
is creating new attributes, which the class happily ignores.  You
probably want either:

    c = canvas.Canvas("pythonJpg.pdf", pagesize=im.size,
pageCompression=1, verbosity=0)
or
    c.setPageSize( im.size )
    c.setPageCompression( 1 )
There is no method for setting verbosity.

However, your test program worked perfectly for me.  It created the
default page size (A4), and placed the image at the bottom left, as one
would expect.

-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.



More information about the reportlab-users mailing list