Prawn::Rtl::Support
This gem provides bidirectional text support for Prawn PDF generator. It uses the Unicode Bidirectional Algorithm via ICU (International Components for Unicode) for text reordering and implements Arabic letter shaping similar to Arabic Letter Connector. Prawn patching is minimal - we only patch Prawn::Text::Formatted::Box#original_text
.
Supported Languages
-
Full support (with contextual letter shaping):
- Arabic
- Persian/Farsi
- Urdu
- Other Arabic script languages
-
RTL support (bidirectional text reordering):
- Hebrew
- Syriac
- Thaana
- Mixed LTR/RTL text
Motivation
Ruby and Rails internally provide Unicode string normalization. However, Prawn doesn't connect Arabic letters into their contextual forms and doesn't support mixed LTR and RTL strings. This gem adds this support.
Requirements
ICU Library
Starting from version 0.2.0, this gem requires the ICU library to be installed on your system:
-
Linux: Usually pre-installed. If not, install with:
# Ubuntu/Debian sudo apt-get install libicu-dev # RHEL/CentOS/Fedora sudo yum install libicu-devel
-
macOS: Install via Homebrew:
brew install icu4c
-
Windows: Download and install ICU from the official site
-
Custom installation path: If ICU is installed in a non-standard location, set the
ICU_LIB_PATH
environment variable:export ICU_LIB_PATH=/custom/path/to/icu/lib
Installation
Add this line to your application's Gemfile:
gem 'prawn-rtl-support'
And that's all. Your Prawn is patched!
Or install it yourself as:
gem install prawn-rtl-support
Usage
prawn-rtl-support
provide method Prawn::Rtl::Connector#fix_rtl(string)
which reverse string and connect arabic letters.
Prawn patching is minimal, we patch only Prawn::Text::Formatted::Box#original_text
.
Development
Check CLAUDE.md for more details about the architecture and development commands.
After checking out the repo, run bin/setup
to install dependencies. Then, run rake spec
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/prawn-rtl-support/prawn-rtl-support. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
Acknowledgment
This gem uses the same code as Arabic Letter Connector by @staii and therefore is based on Arabic-Prawn by Dynamix Solutions (Ahmed Nasser).
License
The gem is available as open source under the terms of the MIT License.