Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ReportLab Image is drawn" on the canvas.Canvas

Tags:

reportlab

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?

like image 405
Daryl Avatar asked May 26 '11 10:05

Daryl


2 Answers

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()
like image 82
Software Enthusiastic Avatar answered Sep 18 '22 11:09

Software Enthusiastic


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.

like image 31
G Gordon Worley III Avatar answered Sep 16 '22 11:09

G Gordon Worley III