Khairy
Khairy

Reputation: 81

ReportLab: Arabic characters are displayed as black squares.

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.

Upvotes: 2

Views: 2069

Answers (1)

Krutarth Buch
Krutarth Buch

Reputation: 26

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.

Upvotes: 1

Related Questions