python生成pdf文件

添加语句,添加图片,定义字体

1
2
3
4
5
6
7
8
9
from reportlab.pdfgen import canvas
c=canvas.Canvas("hello.pdf")
c.drawString(100,700,"hello")
c.drawImage("123.jpg",1*inch,1*inch,width=8*inch,height=9*inch)
c.save()

from reportlab.pdfbase.cidfonts import UnicodeCIDFont
pdfmetrics.registerFont(UnicodeCIDFont('STSong-Light'))
c.setFont("STSong-Light",12)