Skip to content

Version 4.4.0, April 2025, contains our first attempts to support both Shaping and RTL. This means that we can now output languages such as Arabic, Hebrew and Persian, as well as potentially Indic scripts, Thai and Khmer.

This has been a large project. Browsers use libraries which do this; in PDF we need to work out the position of every sentence fragment and glyph. We're using HarfBuzz to tell us the output to display, based on the input.

This feature should be considered experimental. We've been learning this primarily using Google Translate, and visually comparing their output to ours. We will need help from native speakers of these languages to be sure it is correct, and to explore a wide variety of sample formatting situations.
Therefore, this is being included in an experimental release to get wider feedback.

There is a new package rlbidi currently only hosted on our own repository, which will either be folded in to our code or published on PyPi in a later release.

Right to Left texts (RTL) - background

ReportLab now supports right-to-left (RTL) languages such as Arabic, Hebrew and Persian. Some additional steps are needed since RTL support isn't native in the same way as left-to-right text.

Right-to-Left (RTL) texts require special processing because they follow unique linguistic and typographic rules that differ significantly from Left-to-Right (LTR) languages like English.

1) Multiple forms

In languages like Arabic, each letter can have up to four different forms depending on its position in the word:

Isolated (standalone)
Initial (start of the word)
Medial (middle of the word)
Final (end of the word)

For example, the Arabic letter "م" (Meem) changes shape as follows:

م (Isolated)
مـ (Initial)
ـمـ (Medial)
ـم (Final)

Without proper reshaping, the text may appear as disconnected characters, like this:

مرحبا (Correct) م ر ح ب ا (Incorrect) م (Isolated) مـ (Initial) ـمـ (Medial) ـم (Final)

2) Bidirectional Text (BiDi) Handling

RTL languages often include mixed-direction content — for example, Arabic text containing English words or numbers.

Example: أنا أحب Python 3.12 (This sentence reads from right to left, but "Python 3.12" should still read left to right.)

This requires a bidirectional algorithm to maintain correct text flow and alignment. The library python-bidi handles this by reversing the order of RTL characters when needed.

3) Ligatures

Arabic scripts often use ligatures, where multiple characters combine into a single, flowing glyph. Without this feature, the text may appear fragmented.

Example: لا (lam + alef) forms a special ligature in Arabic.

4) Text Alignment

RTL text should be aligned right-to-left by default. Standard text engines in ReportLab (and other Western-oriented tools) default to left alignment, so manual adjustments are needed.

5) Numerals and Symbols

Arabic text may include Arabic numerals (١, ٢, ٣) or Western digits (1, 2, 3). Proper placement and flow are essential in mixed-direction content.

Quick set up

1) Install latest reportlab or rlextra version > 4.4.0 pip install reportlab -i https://www.reportlab.com/pypi or for commercial customers pip install rlextra -i https://www.reportlab.com/pypi

2) pip install rlbidi -i https://www.reportlab.com/pypi

3) Ensure you are using a TrueType font.

4) Within Report Markup Language - Add wordWrap="RTL" to a paragraph style or paragraph. We recommend inheriting your usual style, and right-aligning for the obvious reason that

`<paraStyle name="normal_arabic" parent="normal" wordWrap="RTL" alignment="right"/>`

4) Use a Suitable Font - RTL languages often require specific fonts that include proper glyphs and ligatures. Fonts like Amiri, Noto Naskh Arabic, or Tahoma are commonly used. Arial seems to give reasonable results for Arabic.

Example

ReportLab Plus

Our examples repo and our test suite now include an Arabic test document, with output and with images from Google Translate showing how it's supposed to look:

reportlab Open Source

See reportlab/tests/test_arabic.py which produces several output PDFs We are NOT formally documenting the API at this time as it is highly likely to change as this stabilises.

What Next?

If this is useful to you, please try it out and report anything to us. Commercial customers and enquiries should be emailed to enquiries@reportlab.com; open source users can come on our mailing list https://groups.google.com/g/reportlab-users or https://pairlist2.pair.net/mailman/listinfo/reportlab-users

Continued development for this will require customers needing these languages!