[reportlab-users] Corrupt PDF when including image

Michael Johnson mjjohnson.geo at yahoo.com
Thu Feb 9 16:41:01 EST 2012



> From: Tim Roberts <timr at probo.com>



>> c = canvas.Canvas('test.pdf', 'letter')

>

> The Canvas object does not accept a string as a pagesize.  What I see

> when I open the PDF is that the page size is whacked out.  If you

> replace this with the proper method:

>     from reportlab.lib.pagesizes import letter

>     c  = canvas.Canvas('test.pdf', letter )

> then it works fine.

>

> One could argue that it is a bug for Canvas not to check the type.  It

> expects pagesize to be a 2-tuple.  What happens here is that it uses

> pagesize[0] as the width and pagesize[1] as the height.  In this case,

> that's ord('l') and ord('e'), which result in a very small

> page.

>



Ah, that fixed it. :) I feel a little silly now, but thanks a ton for spotting the mistake! I agree that it would be nice if it checked the type, but the issue was clearly my fault. If there's a bug tracker somewhere I'd be happy to submit this as a minor/wishlist bug.

Michael


More information about the reportlab-users mailing list