在上一篇《Python reportlab库之hello world》中我们演示了简单Demo,在Demo中使用Canvas对象。
from reportlab.pdfgen import canvas
def hello(c):
c.drawString(100,100,"Hello World")
c = canvas.Canvas("hello.pdf")
hello(c)
c.showPage()
c.save()
本篇文章将简单介绍一下Canvas对象,首先我先来看看Canvas的构造函数
def __init__(self,filename,
pagesize=(595.27,841.89),
bottomup = 1,
pageCompression=0,
encoding=rl_config.defaultEncoding,
verbosity=0
encrypt=None)
filename参数控制最终PDF文件的名称
pagesize 参数有width和height两个参数,canvas默认的大小是A4纸(美国标志信件采用的就是A4),具体demo如下
from reportlab.pdfgen import canvas
from repor