4

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、ReportLab2.5を使用しています。システムはUbuntu11.0464ビットです。.oyファイルもUTF-8でエンコードされています。PDFをDocumentViewer2.32.0、Okular 0.12.2、およびAdobe Reader 9で表示すると、黒いボックスが表示されます。

どんな助けでも大歓迎です、ありがとう。

4

1 に答える 1

1

公式の例「追加フォント」のようにフォント名を指定する必要があります。とを使用additional_fontsdefault_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')

ObjectValue()名前付きパラメータもありますstyle:

elements = [ObjectValue(attribute_name='name', style={'fontName': 'wqy'})]

このフォントはオープンソースで、ここからダウンロードできます: http://sourceforge.net/projects/wqy/files/ (Ubuntu 11.04 に同梱されていると思います)

于 2011-08-31T06:22:43.813 に答える