I am trying to generate a pdf file, using python reportlab, but is seems image is displayed with strange black border in pdf.
Here is the code:
# Standalone script to generate pdf lessons
from report开发者_如何学Clab.pdfgen import canvas
def hello(c):
c.drawImage("./media/files/1.png", 0, 600, 350, 350)
c = canvas.Canvas("hello.pdf")
hello(c)
c.showPage()
c.save()
The image I am trying to add is here
Can somebody advice why the black line on the left have appeared, and how to fix it?
The problem isn't with a border, rather your chessboard has transparent pixels on the right and bottom sides, and reportlab isn't recognizing the alpha channel and is painting the transparent section as black:
Using mask='auto'
tells drawImage to use the alpha channel in your PNG, so the background shows through:
c.drawImage("./media/files/1.png", 0, 600, 350, 350, mask='auto')
精彩评论