pdfmake-rtl
v2.1.2
Published
Enhanced PDFMake with comprehensive RTL (Arabic/Persian/Urdu) support - Production ready package
Downloads
952
Maintainers
Readme
pdfmake-RTL

PDFMake RTL is an enhanced version of PDFMake with automatic RTL (Right-to-Left) language support for Arabic, Persian (Farsi), Urdu, and other RTL scripts. No manual configuration needed—just write your content and the library automatically detects and handles RTL text!
All existing PDFMake code works unchanged, with automatic RTL support added!
🚀 Key Features
- ✅ Automatic RTL Detection - No need to set
rtlflags - ✅ Smart Table Column Reversal - Arabic/Persian/Urdu tables automatically reverse columns
- ✅ Unicode Script Detection - Supports Arabic, Persian, Urdu, and extensions
- ✅ Automatic Font Selection - Uses appropriate fonts per language
- ✅ Proper Text Alignment - RTL text aligns right, LTR text aligns left
- ✅ List Bullet Positioning - Bullets positioned correctly for RTL lists
- ✅ Mixed Content Support - Handles Arabic/Persian/Urdu/English mixed content
- ✅ 100% PDFMake Compatible - Drop-in replacement for PDFMake
🌐 Live Demo
PDF document generation library for server-side and client-side in pure JavaScript.
Check out the playground and examples.
documentation
For comprehensive guides, API references, and usage examples, visit the official documentation at pdfmake.github.io/docs.
Features
🔤 RTL Language Support
- Automatic RTL detection for Arabic, Persian (Farsi), Urdu, and other RTL scripts
- Smart table column reversal — columns automatically reverse for RTL content
- Automatic font selection — uses Cairo font for Arabic, Persian, and Urdu text
- Proper text alignment — RTL text automatically aligns right, LTR aligns left
- List bullet positioning — bullets and numbers positioned correctly for RTL lists
- Mixed content handling — seamlessly handles Arabic/Persian/Urdu/English in the same document
- Unicode script detection — supports Arabic, Persian, Urdu characters and extensions
🗒️ Supported RTL Languages
| Language | Script | Auto Font | | ----------------- | ------- | --------- | | Arabic | العربية | Cairo | | Persian (Farsi) | فارسی | Cairo | | Urdu | اردو | Cairo | | Other RTL scripts | — | Cairo |
📄 General Features
- line-wrapping,
- text-alignments (left, right, centered, justified),
- numbered and bulleted lists (with RTL-aware bullet positioning),
- tables and columns
- auto/fixed/star-sized widths,
- col-spans and row-spans,
- headers automatically repeated in case of a page-break,
- automatic column reversal for RTL content,
- images and vector graphics,
- convenient styling and style inheritance,
- page headers and footers:
- static or dynamic content,
- access to current page number and page count,
- background-layer,
- page dimensions and orientations,
- margins,
- document sections,
- custom page breaks,
- font embedding (Cairo font included for RTL support),
- support for complex, multi-level (nested) structures,
- table of contents,
- helper methods for opening/printing/downloading the generated PDF,
- setting of PDF metadata (e.g. author, subject).
📦 Installation
npm install pdfmake-rtl
```markdown
## ⚡ Quick Start — Browser (Client-Side)
```html
<!-- Load pdfmake-rtl + fonts -->
<script src="https://unpkg.com/pdfmake-rtl/build/pdfmake.min.js"></script>
<script src="https://unpkg.com/pdfmake-rtl/build/vfs_fonts.js"></script>
<!-- <script src="https://unpkg.com/pdfmake-rtl/build/fonts/Cairo.js"></script> -->
<script>
var dd = {
rtl: true,
// If Cairo font isn't applied automatically, set `rtl: true` to force RTL mode or add defaultStyle:{font:'Cairo'}
content: [
// RTL paragraph — auto-detected, no configuration needed
{ text: "مرحباً بكم في مكتبة pdfmake-rtl", fontSize: 20, bold: true },
{
text: "هذه المكتبة تدعم اللغة العربية تلقائياً",
margin: [0, 0, 0, 15],
},
// RTL table — columns auto-reverse for Arabic content
{
table: {
// rtl:true
widths: ["*", "*", "*"],
body: [
[
{ text: "الراتب", bold: true },
{ text: "القسم", bold: true },
{ text: "الاسم", bold: true },
],
["5000", "تكنولوجيا", "أحمد محمد"],
["6000", "تسويق", "فاطمة علي"],
],
},
},
// Force RTL on any table with rtl: true
{
table: {
rtl: true,
widths: ["*", "*", "*"],
body: [
[
{ text: "Status", bold: true },
{ text: "Name", bold: true },
{ text: "#", bold: true },
],
["Active", "Ali Hassan", "1"],
["Active", "Sara Ahmed", "2"],
],
},
},
],
};
pdfMake.createPdf(dd).open();
</script>📄 See the full working example:
examples/simple-rtl-table.html
⚡ Quick Start — Node.js (Server-Side)
var pdfmake = require("pdfmake-rtl");
// Add fonts
// Cairo is the default font for RTL languages (Arabic, Persian, Urdu)
// Roboto is the default font for LTR/Latin text
var Roboto = require("pdfmake-rtl/fonts/Roboto");
pdfmake.addFonts(Roboto);
var Cairo = require("pdfmake-rtl/fonts/Cairo");
pdfmake.addFonts(Cairo);
var dd = {
// If Cairo font isn't applied automatically, set `rtl: true` to force RTL mode or add defaultStyle Cairo
rtl: true, // Forces RTL layout direction for the entire document
content: [
{ text: "مرحباً بكم في مكتبة pdfmake-rtl", fontSize: 20, bold: true },
{
table: {
widths: ["*", "*", "*"],
body: [
[
{ text: "الراتب", bold: true },
{ text: "القسم", bold: true },
{ text: "الاسم", bold: true },
],
["5000", "تكنولوجيا", "أحمد محمد"],
["6000", "تسويق", "فاطمة علي"],
],
},
},
],
};
var pdf = pdfmake.createPdf(dd);
pdf.write("output.pdf").then(() => console.log("PDF created!"));Building from sources
using npm:
git clone https://github.com/aysnet1/pdfmake-rtl.git
cd pdfmake-rtl
npm install
npm run buildusing yarn:
git clone https://github.com/aysnet1/pdfmake-rtl.git
cd pdfmake-rtl
yarn
yarn run buildLicense
MIT
Credits
pdfmake-rtl
- @aysnet1 — Creator & Maintainer
pdfmake (Original Library)
pdfmake is based on a truly amazing library pdfkit (credits to @devongovett).
Thanks to all contributors.
