我尝试在FreeNAS系统下运行以下代码。事实上,我希望该程序可以创建一个PDF文件,并可以在文件中显示中文。
#coding=utf-8
import reportlab.rl_config
reportlab.rl_config.warnOnMissingFontGlyphs = 0
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
from reportlab.pdfgen import canvas
pdfmetrics.registerFont(TTFont('song', 'simsun.ttf'))
from reportlab.lib import fonts
fonts.addMapping('song', 0, 0, 'song')
fonts.addMapping('song', 0, 1, 'song')
import copy
from reportlab.platypus import Paragraph, SimpleDocTemplate, PageBreak
from reportlab.lib.styles import getSampleStyleSheet
stylesheet=getSampleStyleSheet()
normalStyle = copy.deepcopy(stylesheet['Normal'])
normalStyle.fontName ='song'
normalStyle.fontSize = 20
story = []
story.append(Paragraph('<b>你好</b>,中文', normalStyle))
doc = SimpleDocTemplate('hello.pdf')
doc.build(story)