tir*_*isu 6 python unicode reportlab
尝试通过 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
在此链接下找到您的角色:
\n\n\n\n转到表的(utf-inliteral)行。
你会看到一些:\\xc3\\x85像字符。选择你的角色...
然后对于文本输出,在代码中键入如下内容:
\n\nCanvas.drawString(x,y,\'\\xc3\\x85\')=> 它将打印\xc3\x85...
所以你必须将你的字典项目更改为UTF-8 LITERALS,因为它无法理解"b\\u0101s"Unicode,有很多方法可以做到这一点......
此致
\n| 归档时间: |
|
| 查看次数: |
5968 次 |
| 最近记录: |