In reportLab, I need to display an arabic paragraph. I am using arabic-resharper and bidi-algorithm. The problem appears in the algorithm that reverses lines.
My code is:
def format_arabic_paragraph(arabic_text: str, paragraph_style: ParagraphStyle):
reshaped_text = arabic_reshaper.reshape(arabic_text)
bidirectional_text = algorithm.get_display(reshaped_text)
formatted_paragraph = Paragraph(bidirectional_text, paragraph_style)
return formatted_paragraph
arabic_text='وحدة1 وحدة2'
Here's the output:
وحدة2
وحدة1
Here's what I expected:
وحدة1
وحدة2
Reportlab has partial bidirectional support using Fribidi. It is disabled by default. There is an option
rtlSupportinreportlab/rl_settings. See user guide section on site configuration. In my installation, I added a file~/.reportlab_settingsand added the linertlSupport=1.In
ParagraphStyle()setwordWrap="RTL".An example:
This gives me: