Python

python中reportlab中文乱码

下载支持的字体https://github.com/StellarCN/scp_zh/tree/master/fonts

 

放进reportla安装目录C:\Program Files (x86)\Python36-32\Lib\site-packages\reportlab\fonts

 

然后

from
reportlab.pdfbase
import
pdfmetrics

from
reportlab.pdfbase.ttfonts
import
TTFont

from
reportlab.pdfgen
import
canvas

 

pdfmetrics.registerFont(TTFont(‘SimSun’, ‘SimSun.ttf’)) #注册字体

 

# main

if __name__==“__main__”:

c = canvas.Canvas(“hello.pdf”)

c.setFont(psfontname=‘SimSun’,size=12)

c.drawString(200,800,“你好”)

c.showPage()

c.save()

 

 

 

 

 

 

 

闻道有先后
术业有专攻

From: shaynerain.com

By: Shaynerain

LEAVE A RESPONSE

电子邮件地址不会被公开。

Hi, I'm shaynerain, this is my website. www.shaynerain.com