Skip to content
Back to Blog
best practices
November 5, 2026
GuruPDF Team
8 min to read

Right-to-left text in PDFs: bidi, joined letters and why you must not split runs

Arabic and Hebrew in PDFs: how visual order works, why one letter per run breaks joining, and what to test.

PDF has no idea what a paragraph is, and it has no concept of text direction either. A content stream just places glyphs on the page in whatever order you give it. So right-to-left support is entirely the author's job, and a few tempting shortcuts each break something.

Logical order and visual order

Your text is stored in logical order: the order it is typed. The page needs visual order: where each piece lands from left to right. The Unicode Bidirectional Algorithm connects the two.

Take a line of Arabic with a number and an English word in it. The Arabic runs right to left, the number and the word run left to right, and brackets mirror depending on the level they sit at. The base direction comes from the line's first strong letter.

We compute levels per line, cut runs where the level changes, and place the runs in display order following rule L2. That part is well documented. The surprises come next.

Don't split into one run per letter

The obvious idea is to place each letter separately, right to left. It breaks Arabic immediately.

Arabic letters have up to four forms, and shaping happens inside a run. Letters drawn one per run come out in isolated forms, and the words stop joining. The whole right-to-left run must go to the shaper as one piece.

Our first version had a green test suite and exactly this bug. A reviewer found it by running real input, not by reading tests.

Don't add ActualText

ActualText lets you say "these glyphs mean this text", and it's very useful for complex left-to-right scripts. On right-to-left text it backfires: viewers that honour it, like PDFium and Acrobat, copy the reversed letters. We use it for Indic scripts and never for Arabic or Hebrew.

Invisible characters are real work

Zero-width joiners, the Arabic letter mark and isolates have no ink, but they matter.

A shaper may lay a ZWNJ out as the space glyph with zero advance. Hand that to a drawing routine and you get a full-width space in the middle of a Persian word. And never cut a run at a ZWJ, because the letter next to it turns isolated.

Some are also level boundaries. A boundary neutral like ZWJ stays at the embedding level in some implementations, which can cut a run in exactly the wrong spot. We give it the level of the character it belongs with.

Marks: keep the text layer and the ink apart

Hebrew points and Arabic harakat were the hardest part. Drawing marks as text at their positions broke copying in every design we tried: one reader put marks before letters, another split the line.

What worked was separating the two. The text object stays exactly what a plain draw would produce. Where a mark needs to move, the code shows a blank and the ink is drawn after it as path-only glyph stamps at the shaper's positions. Readers see clean text, and people see correct marks.

Reading it back

If your tool can edit existing PDFs, you have to go the other way too. Extractors return right-to-left lines in odd orders, and producers disagree on mirroring: some write the shown bracket in ToUnicode, others the typed one. We read each line both ways and let its brackets vote, then keep a reading only if re-laying it out gives the same levels as what was drawn.

How to test this

  • Judge by the render, not by one reader's extracted text. Some viewers lose the space next to a number in an RTL line.
  • Pin byte-identical output for text with nothing right to left, so the fix can't change other documents.
  • Keep the preview honest. In a browser, unicode-bidi: plaintext with a physical text-align matches a bake that always starts from the left edge.

You can try this in our PDF editor, and there is an Arabic guide for readers.