2

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.

Khairy
  • 81
  • 1
  • 10

1 Answers1

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.

dokaspar
  • 8,186
  • 14
  • 70
  • 98