Download the PHP package mostafamoknaa/laravel-arabic-pdf without Composer
On this page you can find all versions of the php package mostafamoknaa/laravel-arabic-pdf. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mostafamoknaa/laravel-arabic-pdf
More information about mostafamoknaa/laravel-arabic-pdf
Files in mostafamoknaa/laravel-arabic-pdf
Package laravel-arabic-pdf
Short Description Generate PDFs with correct Arabic text in Laravel: connected letters (glyph shaping), right-to-left word order (bidi) and RTL tables, built on dompdf.
License MIT
Homepage https://github.com/mostafamoknaa/laravel-arabic-pdf
Informations about the package laravel-arabic-pdf
Laravel Arabic PDF
Generate PDFs with correct Arabic text in Laravel.
dompdf, the most used PDF library in Laravel, has no Arabic support. The letters come out disconnected (م ح م د instead of محمد) and the words are reversed. This package fixes both, with no changes to your Blade views:
- Connected letters: every letter gets its correct initial / medial / final / isolated form, plus the lam-alef ligatures (لا، لأ، لإ، لآ).
- Right-to-left order: words are placed right to left using the Unicode Bidirectional Algorithm, while numbers, prices, percentages and English words stay left to right.
- Mixed content:
<b>,<span>,<a>, … inside Arabic paragraphs are placed correctly. - RTL tables: columns go from right to left inside
dir="rtl". - Multi-line paragraphs: optional line wrapping so long paragraphs don't read bottom to top.
- Persian letters (پ چ ژ گ ک ی) are supported too.
بالعربي: حزمة Laravel لإنشاء ملفات PDF باللغة العربية بشكل صحيح: الحروف متصلة، والكلمات بترتيبها الصحيح من اليمين لليسار، مع الحفاظ على الأرقام والكلمات الإنجليزية، ودعم الجداول والنصوص الطويلة.
Requirements
- PHP 8.1+
- Laravel 10, 11, 12 or 13
ext-domandext-mbstring
Installation
The service provider and the ArabicPdf / Arabic facades are registered automatically.
To publish the config file (optional):
Usage
1. Create a Blade view
Add dir="rtl" to <html> (or to any element) so text is right-aligned and tables go right to left.
2. Generate the PDF
All methods
Long paragraphs
dompdf wraps lines itself, without knowing about Arabic. A long paragraph would therefore show its last words on the first line. To avoid this, wrap long paragraphs at a number of characters with the data-arabic-wrap attribute:
Or set max_chars_per_line in config/arabic-pdf.php to apply it everywhere. Choose a value that fits the width of your column and font size. Short texts (titles, labels, table cells) don't need it.
Using only the text helpers
Already using barryvdh/laravel-dompdf or another library? Use the Arabic facade to fix the HTML or the text yourself:
Or the @arabic Blade directive (escaped output):
Don't use @arabic inside views that go through ArabicPdf::loadView(), since those are already fixed automatically. Fixing twice is safe but unnecessary.
Skipping elements
Add data-arabic-skip to keep an element's text as it is:
<script>, <style>, <textarea> and <svg> are always skipped.
Fonts
The font must contain the Arabic Presentation Forms glyphs (U+FB50–U+FDFF and U+FE70–U+FEFF). DejaVu Sans ships with dompdf, has them, and is the default font. To use another font, register it with @font-face (a TTF file inside your project):
Many modern web fonts only support Arabic through OpenType features and don't include these glyphs. If you see empty boxes or "?", your font is missing them, so try another font.
Configuration
How it works
- Your view is rendered to HTML and parsed with PHP's DOM extension.
- Each Arabic text node is shaped: letters are replaced by their contextual presentation forms (for example ب becomes ﺑ, ﺒ, ﺐ or ﺏ depending on its neighbours).
- The text is reordered from logical to visual order with the Unicode Bidirectional Algorithm. Arabic runs are reversed, while numbers and Latin runs keep their direction, and brackets are mirrored.
- Inline elements inside RTL paragraphs and table cells inside
dir="rtl"are reordered too. - The result is passed to dompdf, which just draws it left to right.
Testing
Contributing
Pull requests are welcome. Please add a test for any bug fix or new feature.
License
The MIT License (MIT). See LICENSE.md.
All versions of laravel-arabic-pdf with dependencies
ext-dom Version *
ext-mbstring Version *
dompdf/dompdf Version ^2.0|^3.0
illuminate/http Version ^10.0|^11.0|^12.0|^13.0
illuminate/support Version ^10.0|^11.0|^12.0|^13.0
illuminate/view Version ^10.0|^11.0|^12.0|^13.0