Python Unicode字符是Geraldo/ReportLab生成的PDF中的框

Python Unicode字符是Geraldo/ReportLab生成的PDF中的框,python,pdf,unicode,reportlab,geraldo,Python,Pdf,Unicode,Reportlab,Geraldo,在使用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

在使用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时,黑框可见


非常感谢您的帮助。

您应该按照官方示例“”指定字体名称。使用
附加字体
默认字体

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from geraldo import Report, ReportBand, ObjectValue
from geraldo.generators import PDFGenerator

class UnicodeReport(Report):    
    title = 'Report'
    additional_fonts = {
        'wqy': '/usr/share/fonts/wqy-zenhei/wqy-zenhei.ttc'
    }
    default_style = {'fontName': 'wqy'}

    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')
elements = [ObjectValue(attribute_name='name', style={'fontName': 'wqy'})]
ObjectValue()
还有一个命名参数
style

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from geraldo import Report, ReportBand, ObjectValue
from geraldo.generators import PDFGenerator

class UnicodeReport(Report):    
    title = 'Report'
    additional_fonts = {
        'wqy': '/usr/share/fonts/wqy-zenhei/wqy-zenhei.ttc'
    }
    default_style = {'fontName': 'wqy'}

    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')
elements = [ObjectValue(attribute_name='name', style={'fontName': 'wqy'})]

这种字体是开源的,可以在这里下载:(我想它是Ubuntu 11.04附带的)

你在用什么?您正在测试的机器上安装了吗?谢谢,现在亚洲字符出现了!在我的设置中,必须运行“sudo apt get install ttf wqy zenhei”,因为wqy zenhei不是标准的CD发行版(它在DVD发行版上)。这会将字体安装到“/usr/share/fonts/truetype/wqy/wqy zenhei.ttc”。