ReportLab's Image is coming out mirrored on the PDF Canvas with 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 have it drawn 'normally', as one would expect to see it?
Use 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()
I can't test at the moment, but it's possibly because of bottomup = 0
in your creation of the Canvas
object. The default is 1
. From the documentation:
The bottomup argument switches coordinate systems. Some graphics systems (like PDF and PostScript) place (0,0) at the bottom left of the page others (like many graphical user interfaces [GUI's]) place the origen at the top left. The bottomup argument is deprecated and may be dropped in future
Need to see if it really works for all tasks, and if not then get rid of it
Given the warnings in that quote, my guess is that setting it to 0
is the source of the problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With