reportlab中如何写中文

https://www.jianshu.com/p/41284e4e25f5

 

https://github.com/StellarCN/scp_zh/blob/master/fonts/SimSun.ttf

 

 

from reportlab.lib.colors import blue
from reportlab.lib.pagesizes import LETTER,A4
from reportlab.lib.units import inch
from reportlab.pdfgen.canvas import Canvas

from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont

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

canvas = Canvas("./PythonScript/Financial Statements.pdf", pagesize=LETTER)
# Set font to Times New Roman with 12-point size
canvas.setFont("SimSun", 25)

# Draw blue text one inch from the left and ten
# inches from the bottom
canvas.setFillColor(blue)

canvas.drawString(4.25 * inch, 10 * inch, r"报表")
canvas.drawString(4.25 * inch, 9 * inch, r"Results")

# Save the PDF file
canvas.save()
posted @ 2020-10-21 12:54  bH1pJ  阅读(51)  评论(0编辑  收藏  举报