MonkeybreadSoftware Posted Saturday at 05:58 PM Posted Saturday at 05:58 PM Rendering text in a PDF might seem straightforward—until you try working with languages like Arabic or Hebrew. These languages require more than just placing characters from left to right. Without proper handling, the result can be unreadable or even misleading. Let’s look at how DynaPDF handles this challenge using Bidirectional (Bidi) Mode and Complex Text Rendering. The Problem with Basic Text Rendering When rendering Latin-based languages like English, you can often get away with simply passing text directly to DynaPDF and letting it handle the rest. But try the same with Arabic, and you’ll see this: Anyone who reads Arabic would instantly notice something's wrong. Arabic, like many other languages, has context-sensitive glyph shaping. The shape of a character can change depending on whether it appears at the beginning, middle, or end of a word. On top of that, the text flows right-to-left, adding more complexity. Enter Bidirectional Mode To handle this, DynaPDF offers Bidi Mode. When enabled, this mode uses the Unicode Bidirectional Algorithm, as defined by the Unicode Consortium, to determine how to properly order characters in a mixed left-to-right (LTR) and right-to-left (RTL) context. DynaPDF supports the entire UCS-2 character range and handles most use cases well. However, the results can differ slightly from what you'd get using Microsoft's Uniscribe, which is often used in Windows applications to process complex text. If you need to match Uniscribe’s output, you should: Pre-process your text using Uniscribe or a similar Unicode library. Disable the internal Bidi algorithm in DynaPDF. Load the font with the Unicode code page to maintain compatibility. Once you do this, your output will look like this: Using Complex Text Rendering On Windows, DynaPDF can take this even further using the ComplexText flag. When enabled, this lets DynaPDF **leverage Uniscribe to perform both bidirectional processing and advanced glyph shaping, all before the text is rendered. This results in output that is significantly more legible and natural for RTL languages like Arabic: Best Practices for Arabic (and RTL) Text If you're working with Arabic or any RTL language in DynaPDF, follow these recommendations: Enable BidiMode = RightToLeft This activates the Unicode Bidirectional Algorithm. Enable ComplexText (on Windows) This allows DynaPDF to use Uniscribe for shaping and ordering. Pre-process text using an external Unicode library (if needed) Especially when working on non-Windows platforms or aiming to match a specific rendering engine. Use Unicode fonts Make sure your fonts support the full range of characters and glyphs needed for the language. With these tools, DynaPDF makes it possible to render complex languages properly, whether you're creating invoices in Arabic or supporting multilingual user interfaces. If you need help setting this up in your application, feel free to reach out—we’re happy to help you get beautiful, readable results!
Recommended Posts