尝试通过 python 3 使用 reportlab 编写包含宏宏的文档 (\xc4\x81 \xc4\x93 \xc4\xab \xc5\x8d \xc5\xab),但宏宏显示为框 (\xe2\x96 \xa0). 该文档是用 Arial 字体编写的 - 但如果我在文字处理程序中打开该文件来检查字体,则这些框采用“Segoe UI Symbol”字体。
\n\n要在 Arial 中导入为支持多种 unicode 字符的字体(这似乎有效):
\n\nimport reportlab.rl_config\nreportlab.rl_config.warnOnMissingFontGlyphs = 0\nfrom reportlab.pdfbase import pdfmetrics\nfrom reportlab.pdfbase.ttfonts import TTFont\npdfmetrics.registerFont(TTFont(\'Arial\', \'Arial.ttf\'))\nRun Code Online (Sandbox Code Playgroud)\n\n我还通过 json 导入字典,当我在记事本中打开 json 文件时,看起来像这样:
\n\n{"example1":"b\\u0101s"}\nRun Code Online (Sandbox Code Playgroud)\n\n该程序读取并写入这个字典:
\n\nfrom reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer\nfrom reportlab.lib.styles import getSampleStyleSheet\ndoc = SimpleDocTemplate("hello.pdf")\nStory = [Spacer(1,2*inch)]\nstyle = styles["Normal"]\nwith open(\'CompDict.json\',\'r\') as f:\n m_dic=json.load(f)\nfor key,value in m_dic:\n p=Paragraph(key+":"+value,style)\n Story.append(p)\ndoc.build(Story)\nRun Code Online (Sandbox Code Playgroud)\n\n结果应该是一个 pdf 文件,example1:b\xc4\x81s但结果却是example1:b\xe2\x96\xa0s …