在使用 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 编码的。在 Document Viewer 2.32.0、Okular 0.12.2 和 Adobe Reader 9 中查看 PDF 时,黑框可见。
非常感谢任何帮助,谢谢。