ReportLab: Arabic characters are displayed as black squares.

跟風遠走 提交于 2020-01-02 09:56:41

问题


I try for weeks to create pdf reports in Arabic, but I failed. I use ReportLab with two packages for building the Arabic characters namely bidi.algorithm and arabic_reshaper. In the console the characters are well organized but in the pdf there are only black square.

import reshaper
from bidi.algorithm import get_display
heading = get_display(reshaper.reshape(unicode('العربية', encoding='utf-8')))
print heading

The output in console : العربية

But in the generated pdf file : ▀ ▀ ▀ ▀ ▀

Thank you in advance.


回答1:


I faced the same problem and came up with the following solution:

import reshaper
from bidi.algorithm import get_display
from reportlab.platypus import SimpleDocTemplate, Paragraph
from reportlab.pdfbase import pdfmetrics
from reportlab.lib.styles import ParagraphStyle
from reportlab.pdfbase.ttfonts import TTFont

arabic_text = reshaper.reshape(u'العربية')
arabic_text = get_display(arabic_text)
pdfmetrics.registerFont(TTFont('Arabic-bold', '/path-to-your-arabic-font'))

Then you have to setFont 'Arabic-bold' for displaying it in pdf file.



来源:https://stackoverflow.com/questions/22512779/reportlab-arabic-characters-are-displayed-as-black-squares

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!