reportlab之Coordinates坐标修改

2022-04-06  本文已影响0人  我就是鱼鱼鱼

Coordinates

主要用于控制坐标系

def coords(canvas):
    from reportlab.lib.units import inch
    from reportlab.lib.colors import pink, black, red, blue, green
    c = canvas
    #画一个粉红色的网格线,grid后面的参数为网格线的长宽等
    c.setStrokeColor(pink)
    c.grid([inch,2*inch,3*inch,4*inch],[0.5*inch,inch,1.5*inch,2*inch,2.5*inch])
    #写一个黑的的文本
    c.setStrokeColor(black)
    c.setFont('Times-Roman',20)
    c.drawString(0,0,"(0,0) the origin")
    c.drawString(2.5*inch,inch,"(2.5,1) in inches")
    c.drawString(4*inch,2.5*inch,"(4,2.5)")
    #画一个红色的柱子
    c.setFillColor(red)
    c.rect(0,2*inch,0.2*inch,0.3*inch,fill=1)
    #画一个绿色的圆
    c.setFillColor(green)
    c.circle(4.5*inch,0.4*inch,0.2*inch,fill=1)

效果展示如下:


Coordinates.png

translate

移动原点,我理解应该是直接将pdf上所有的内容移动

def translate(canvas):
    from reportlab.lib.units import cm 
    canvas.translate(z.3*cm,0.3*cm)
    coords(canvas)
translate.png

压缩和拉长Shrinking and growing

def scale(canvas):
    canvas.scale(0.75,0.5)
    coords(canvas)
Shrinking and growing.png

镜像Mirror

def mirror(canvas):
    from reportlab.lib.units import inch
    canvas.translate(5.5*inch,0)
    canvas.scale(-1.0,1.0)
    coords(canvas)
mirror.png
上一篇下一篇

猜你喜欢

热点阅读