我尝试了几个星期用阿拉伯语创建 pdf 报告,但失败了。
我使用 ReportLab 和两个包来构建阿拉伯字符,即 bidi.algorithm 和 arabic_reshaper。
在控制台中,字符组织良好,但在 pdf 中只有黑色方块。
import reshaper
from bidi.algorithm import get_display
heading = get_display(reshaper.reshape(unicode('العربية', encoding='utf-8')))
print heading
控制台的输出:
但在生成的pdf文件中: ▀ ▀ ▀ ▀ ▀
先感谢您。
我遇到了同样的问题并提出了以下解决方案:
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'))
然后你必须设置字体'Arabic-bold'才能在pdf文件中显示它。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)