2011-05-26 196 views
5

ReportLab的形象是走出上的PDF画布镜像用下面的代码片段:ReportLab的图像绘制”关于canvas.Canvas

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) 

如何拥有它绘制‘正常的’,如一个希望看到它

回答

3

我不能在此刻测试,但它在你的Canvas对象的创建是可能是因为bottomup = 0默认为1documentation:。

自底向上参数切换坐标系。一些图形系统(如PDF和PostScript)将页面左下方的(0,0)放置在其他页面(如许多图形用户界面[GUI]),将origen放在左上角。在自下而上的说法已过时,并且可能会在未来

需要被丢弃,看它是否真的适用于所有的任务,如果没有的话摆脱它

鉴于该报价的警告,我的猜测是将其设置为0是问题的根源。

+0

你是对的,这是因为自下而上设置为0. – sepulchered 2012-11-10 13:07:43

+2

关于如何解决这个问题,同时保持'bottomtop'设置为0的任何想法? – Voles 2013-03-13 13:32:17

4

使用canvas.scale函数来翻转图像。

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

用左下角的原点(0,0)绘制图片。

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

H是页面高度。