1

我尝试在 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)
4

0 回答 0