[reportlab-users] drawImage produces blank page only
Larry Bates
larry.bates at websafe.com
Thu Dec 29 17:37:01 EST 2005
----------------------------------------------------------------------
>Message: 1
>Date: Thu, 29 Dec 2005 11:05:41 -0500 (EST)
>From: "Bernd Prager" <bernd at prager.ws>
>Subject: [reportlab-users] drawImage produces blank page only
>To: reportlab-users at reportlab.com
>Message-ID: <46868.198.45.19.20.1135872341.squirrel at mail.prager.ws>
>Content-Type: text/plain;charset=iso-8859-1
>
>Hi,
>
>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.
>
>When I import that document in Photoshop I can actually see the image
>though. I don't know what that means, but it seems the pdf file is somehow
>broken?
>
>I also tried different image formats (tiff, pbm and jpg).
>Do I do anything wrong?
>
>Thanks for help,
>-- Bernd
>
>
>
>
>
I think your problem is in the sizing. ReportLab defines pages in points.
im.size returns pixels. You must define your pagesize in points and then
drawInlineImage on it.
This works for me (not tested). Try:
from reportlab.lib.pagesizes import letter
formwidthinpoints, formheightinpoints=letter
Canvas=canvas.Canvas(FAX.PDFfilename, pageCompression=1,
formwidthinpoints, formheightinpoints=letter
Canvas.drawInlineImage('out300.jpg', 0, 0,
pagesize=letter)
Larry Bates
More information about the reportlab-users
mailing list