[reportlab-users] Corrupt PDF when including image

Andy Robinson andy at reportlab.com
Thu Feb 9 16:50:44 EST 2012


Good catch, Tim. In ten years I have not seen this before. We should definitely add a type check to prevent it recurring...

Andy Robinson
ReportLab

On 9 Feb 2012, at 20:43, Tim Roberts <timr at probo.com> wrote:


> Michael Johnson wrote:

>> I just started using reportlab (2.5) for a project I'm working on, and the PDFs that I'm generating can't be opened by either Ghostscript 9.04 or Acrobat 9. However, they open fine in Okular and in Gmail's PDF preview. I did some searching and found that for PDFs that include images, sometimes a particular image will cause problems. However, I tried switching to a completely different image and had no better luck. Here's a minimum working Python example:

>>

>> #!/usr/bin/env python

>>

>> from reportlab.lib.units import inch

>> from reportlab.lib.utils import ImageReader

>> from reportlab.pdfgen import canvas

>>

>> bg = "test_image.png"

>> 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.

>

> --

> Tim Roberts, timr at probo.com

> Providenza & Boekelheide, Inc.

>

> _______________________________________________

> reportlab-users mailing list

> reportlab-users at lists2.reportlab.com

> http://two.pairlist.net/mailman/listinfo/reportlab-users



More information about the reportlab-users mailing list