2014-03-19 30 views
2

我嘗試了幾個星期來創建阿拉伯語的PDF報告,但我失敗了。 我使用ReportLab和兩個包來構建阿拉伯字符,即bidi.algorithm和arabic_reshaper。 在控制檯中,字符組織良好,但在pdf中只有黑色方塊。ReportLab:阿拉伯字符顯示爲黑色方塊。

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

在控制檯輸出:العربية

但在生成的PDF文件:▀▀▀▀▀

預先感謝您。

+0

請問您可以添加一個最小且可運行的代碼示例嗎? – Fookatchu

+0

問題中的代碼是可運行的,但您應該安裝模塊:-Arabic-Reshaper和bidi.algorithm – Khairy

回答

1

我面臨同樣的問題,有以下解決方案上來:

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')) 

然後,你必須setfont程序「阿拉伯大膽」在PDF文件中顯示它。