Unicode 字符是 Geraldo/ReportLab 生成的 PDF 中的方框
使用 Geraldo 和 ReportLab 生成 PDF 报告时,我遇到了一些与 Unicode 相关的问题。
当包含亚洲字符的 Unicode 字符串传递到报表中时,它们在输出 PDF 中显示为黑框。此示例 (http://dl.dropbox.com/u/2627296/report.pdf) 是使用以下代码生成的:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from geraldo import Report, ReportBand, ObjectValue
from geraldo.generators import PDFGenerator
class UnicodeReport(Report):
title = 'Report'
class band_detail(ReportBand):
elements = [ObjectValue(attribute_name='name')]
if __name__ == '__main__':
objects = [{'name': u'한국어/조선말'}, {'name': u'汉语/漢語'}, {'name': u'オナカップ'}]
rpt = UnicodeReport(queryset=objects)
rpt.generate_by(PDFGenerator, filename='/tmp/report.pdf')
我使用的是 Python 2.7.1、Geraldo 0.4.14 和 ReportLab 2.5。系统是Ubuntu 11.04 64位。 .oy 文件也是 UTF-8 编码的。在文档查看器 2.32.0、Okular 0.12.2 和 Adobe Reader 9 中查看 PDF 时,黑框可见。
非常感谢任何帮助,谢谢。
I'm running into some Unicode related issues when generating PDF reports using Geraldo and ReportLab.
When Unicode strings containing Asian characters are passed into the report, they appear in the output PDF as black boxes. This example (http://dl.dropbox.com/u/2627296/report.pdf) was generated using the following code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from geraldo import Report, ReportBand, ObjectValue
from geraldo.generators import PDFGenerator
class UnicodeReport(Report):
title = 'Report'
class band_detail(ReportBand):
elements = [ObjectValue(attribute_name='name')]
if __name__ == '__main__':
objects = [{'name': u'한국어/조선말'}, {'name': u'汉语/漢語'}, {'name': u'オナカップ'}]
rpt = UnicodeReport(queryset=objects)
rpt.generate_by(PDFGenerator, filename='/tmp/report.pdf')
I'm using Python 2.7.1, Geraldo 0.4.14 and ReportLab 2.5. System is Ubuntu 11.04 64-bit. The .oy file is also UTF-8 encoded. The black boxes are visible when the PDF is viewed in Document Viewer 2.32.0, Okular 0.12.2 and Adobe Reader 9.
Any help is greatly appreciated, thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该指定字体名称,如官方示例“其他字体” 。使用
additional_fonts
和default_style
:ObjectValue()
还有一个命名参数style
:这种字体是开源的,可以可以在这里下载:http://sourceforge.net/projects/wqy/files/(我认为这是随 Ubuntu 11.04 一起提供)
You should specify the font name as in the official example "Additional Fonts". Use
additional_fonts
anddefault_style
:ObjectValue()
also has a named parameterstyle
:This font is open source and can be downloaded here: http://sourceforge.net/projects/wqy/files/ (I think it's shipped with Ubuntu 11.04)