from reportlab.pdfgen import canvas from reportlab.lib.pagesizes import letter, landscape c = canvas.Canvas("Test.pdf", pagesize=landscape(letter)) c.drawImage("MYRGeneratedImage.png",0,0) #This wont work c.drawImage("logo.png",350,50) #This works c.showPage() c.save()
Page 1 of 1
1 Replies - 922 Views - Last Post: 25 February 2014 - 02:20 PM
Report Lab Fails to render images
Posted 25 February 2014 - 07:19 AM
I am trying to add an graph I created in R to a pdf using python's ReportLab. When I try it on a PNG that I got off the internet it works fine but when I try it with an image that I created using R it does not work. How do I figure out what is wrong with the image I created? If there some kind of property or something that needs to be set? When I stick the image in the PDF (see example below) it is just a black box. (I can open the PNG in an image viewer and it is not a black box). PIL is installed....
Replies To: Report Lab Fails to render images
Re: Report Lab Fails to render images
Posted 25 February 2014 - 02:20 PM
When I try it on a PNG that I got off the internet it works fine but when I try it with an image that I created using R it does not work
First, check that it is a valid PNG file. The magic number is .PNG but the first character is decimal 137, not a dot. You should be able to view the file, or print the first four characters, and check for dec 137 + "PNG".
Also, you can convert it to any other format and then to PNG using ImageMagick's convert program, which will assure that it is now a valid PNG file.
Which says it is in some other format and the image viewer goes with the magic number and opens it, or the image viewer isn't as strict as the PDF requirements.
(I can open the PNG in an image viewer and it is not a black box)
This post has been edited by woooee: 25 February 2014 - 02:24 PM
Page 1 of 1