ReportLab image painted on canvas.

ReportLab The image goes to the PDF mirror using the following code snippet:

from reportlab.pdfgen import canvas
from reportlab.platypus import Image

pdf = canvas.Canvas(filename, bottomup=0)

logo_image = Image(
    "%s/images/wsp_logo.jpg" % settings.STATIC_ROOT,
    width=200,
    height=200) 
logo_image.drawOn(pdf, 100, 100)

How to draw it β€œnormally”, how could you see it?

+5
source share
3 answers

Use the canvas.scale function to flip the image.

canvas.saveState()
canvas.translate(x, y)
canvas.scale(1,-1)
canvas.drawImage(img_path, 0, 0, width=-width, height=-height, mask='auto')
canvas.restoreState()
+4
source

I cannot check at the moment, but this is possible due to the bottomup = 0creation of the object Canvas. The default is used 1. From the doc:

bottomup . (, PDF PostScript), (, [GUI]), . bottomup

, , , .

, , 0 .

+3

To draw an image with a start point (0,0) in the lower left corner.

canvas.saveState()
canvas.transform(1, 0, 0, -1, 0, H)
draw_your_picture_code()
canvas.restoreState()

H - page height.

0
source

All Articles