@digicole/pdfmake-rtl 1.2.0 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/.vscode/tasks.json +17 -0
  2. package/CHANGELOG.md +83 -128
  3. package/LICENSE +22 -22
  4. package/README.md +188 -681
  5. package/build/fonts/Cairo/Cairo-Black.ttf +0 -0
  6. package/build/fonts/Cairo/Cairo-Bold.ttf +0 -0
  7. package/build/fonts/Cairo/Cairo-ExtraLight.ttf +0 -0
  8. package/build/fonts/Cairo/Cairo-Light.ttf +0 -0
  9. package/build/fonts/Cairo/Cairo-Regular.ttf +0 -0
  10. package/build/fonts/Cairo/Cairo-SemiBold.ttf +0 -0
  11. package/build/fonts/Cairo.js +27 -0
  12. package/build/fonts/Roboto/Roboto-Italic.ttf +0 -0
  13. package/build/fonts/Roboto/Roboto-Medium.ttf +0 -0
  14. package/build/fonts/Roboto/Roboto-MediumItalic.ttf +0 -0
  15. package/build/fonts/Roboto/Roboto-Regular.ttf +0 -0
  16. package/build/fonts/Roboto.js +27 -0
  17. package/build/pdfmake.js +63736 -71285
  18. package/build/pdfmake.js.map +1 -1
  19. package/build/pdfmake.min.js +2 -2
  20. package/build/pdfmake.min.js.map +1 -1
  21. package/build/standard-fonts/Courier.js +27 -0
  22. package/build/standard-fonts/Helvetica.js +27 -0
  23. package/build/standard-fonts/Symbol.js +21 -0
  24. package/build/standard-fonts/Times.js +27 -0
  25. package/build/standard-fonts/ZapfDingbats.js +21 -0
  26. package/build/vfs_fonts.js +11 -7
  27. package/build-vfs.js +44 -44
  28. package/fonts/Cairo/Cairo-Black.ttf +0 -0
  29. package/fonts/Cairo/Cairo-Bold.ttf +0 -0
  30. package/fonts/Cairo/Cairo-ExtraLight.ttf +0 -0
  31. package/fonts/Cairo/Cairo-Light.ttf +0 -0
  32. package/fonts/Cairo/Cairo-Regular.ttf +0 -0
  33. package/fonts/Cairo/Cairo-SemiBold.ttf +0 -0
  34. package/fonts/Cairo.js +8 -0
  35. package/fonts/Roboto/Roboto-Italic.ttf +0 -0
  36. package/fonts/Roboto/Roboto-Medium.ttf +0 -0
  37. package/fonts/Roboto/Roboto-MediumItalic.ttf +0 -0
  38. package/fonts/Roboto/Roboto-Regular.ttf +0 -0
  39. package/fonts/Roboto.js +8 -0
  40. package/index.js +26 -26
  41. package/package.json +42 -39
  42. package/src/3rd-party/svg-to-pdfkit/LICENSE +9 -9
  43. package/src/3rd-party/svg-to-pdfkit/source.js +229 -36
  44. package/src/3rd-party/svg-to-pdfkit.js +3 -3
  45. package/src/OutputDocument.js +64 -0
  46. package/src/OutputDocumentServer.js +32 -0
  47. package/src/PDFDocument.js +174 -0
  48. package/src/PageSize.js +53 -0
  49. package/src/Renderer.js +445 -0
  50. package/src/TextBreaker.js +168 -0
  51. package/src/TextInlines.js +263 -0
  52. package/src/URLResolver.js +43 -0
  53. package/src/base.js +70 -0
  54. package/src/browser-extensions/OutputDocumentBrowser.js +80 -0
  55. package/src/browser-extensions/fonts/Cairo.js +27 -0
  56. package/src/browser-extensions/fonts/Roboto.js +27 -0
  57. package/src/browser-extensions/index.js +61 -0
  58. package/src/browser-extensions/pdfMake.js +1 -355
  59. package/src/browser-extensions/standard-fonts/Courier.js +27 -0
  60. package/src/browser-extensions/standard-fonts/Helvetica.js +27 -0
  61. package/src/browser-extensions/standard-fonts/Symbol.js +21 -0
  62. package/src/browser-extensions/standard-fonts/Times.js +27 -0
  63. package/src/browser-extensions/standard-fonts/ZapfDingbats.js +21 -0
  64. package/src/browser-extensions/virtual-fs-cjs.js +1 -0
  65. package/src/columnCalculator.js +154 -157
  66. package/src/docMeasure.js +802 -810
  67. package/src/docPreprocessor.js +306 -273
  68. package/src/documentContext.js +345 -340
  69. package/src/elementWriter.js +736 -411
  70. package/src/helpers/node.js +136 -0
  71. package/src/helpers/tools.js +44 -0
  72. package/src/helpers/variableType.js +50 -0
  73. package/src/index.js +16 -0
  74. package/src/layoutBuilder.js +1393 -1197
  75. package/src/line.js +122 -104
  76. package/src/pageElementWriter.js +187 -174
  77. package/src/printer.js +370 -727
  78. package/src/qrEnc.js +796 -791
  79. package/src/rtlUtils.js +500 -485
  80. package/src/standardPageSizes.js +52 -54
  81. package/src/styleContextStack.js +208 -138
  82. package/src/svgMeasure.js +109 -70
  83. package/src/tableLayouts.js +100 -0
  84. package/src/tableProcessor.js +620 -606
  85. package/src/textDecorator.js +175 -157
  86. package/src/virtual-fs.js +66 -0
  87. package/standard-fonts/Courier.js +8 -0
  88. package/standard-fonts/Helvetica.js +8 -0
  89. package/standard-fonts/Symbol.js +5 -0
  90. package/standard-fonts/Times.js +8 -0
  91. package/standard-fonts/ZapfDingbats.js +5 -0
  92. package/index.html +0 -396
  93. package/src/browser-extensions/URLBrowserResolver.js +0 -96
  94. package/src/browser-extensions/virtual-fs.js +0 -55
  95. package/src/fontProvider.js +0 -68
  96. package/src/helpers.js +0 -138
  97. package/src/imageMeasure.js +0 -62
  98. package/src/pdfKitEngine.js +0 -21
  99. package/src/textTools.js +0 -391
  100. package/src/traversalTracker.js +0 -47
package/README.md CHANGED
@@ -1,16 +1,31 @@
1
- # PDFMake RTL
2
- [![npm version](https://badge.fury.io/js/%40digicole%2Fpdfmake-rtl.svg)](https://badge.fury.io/js/%40digicole%2Fpdfmake-rtl)
3
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
1
+ <!-- [![Node.js CI][githubactions_img]][githubactions_url] -->
4
2
 
3
+ # pdfmake-RTL [![GitHub][github_img]][github_url] [![npm][npm_img]][npm_url]
4
+
5
+ [githubactions_img]: https://github.com/aysnet1/pdfmake-rtl/actions/workflows/node.js.yml/badge.svg?branch=master
6
+ [githubactions_url]: https://github.com/aysnet1/pdfmake-rtl/actions
7
+ [github_img]: https://img.shields.io/github/release/aysnet1/pdfmake-rtl.svg?colorB=0E7FBF
8
+ [github_url]: https://github.com/bpampuch/pdfmake-rtl/releases/latest
9
+ [npm_img]: https://img.shields.io/npm/v/pdfmake-rtl.svg?colorB=0E7FBF
10
+ [npm_url]: https://www.npmjs.com/package/pdfmake-rtl
11
+ [cdnjs_img]: https://img.shields.io/cdnjs/v/pdfmake-rtl.svg?colorB=0E7FBF
12
+
13
+ <!-- [cndjs_url]: https://cdnjs.com/libraries/pdfmake-rtl -->
5
14
 
6
15
  **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!
7
16
 
8
17
  All existing PDFMake code works unchanged, with automatic RTL support added!
9
18
 
19
+ > **⚠️ Important:** This package has moved to a new npm scope. Please use [`pdfmake-rtl`](https://www.npmjs.com/package/pdfmake-rtl) going forward.
20
+ >
21
+ > ```bash
22
+ > npm install pdfmake-rtl
23
+ > ```
24
+
10
25
  ## 🚀 Key Features
11
26
 
12
- - ✅ **Automatic RTL Detection** - No need to set `supportRTL` flags
13
- - ✅ **Smart Table Column Reversal** - Arabic/Persian/Urdu tables automatically reverse columns
27
+ - ✅ **Automatic RTL Detection** - No need to set `rtl` flags
28
+ - ✅ **Smart Table Column Reversal** - Arabic/Persian/Urdu tables automatically reverse columns
14
29
  - ✅ **Unicode Script Detection** - Supports Arabic, Persian, Urdu, and extensions
15
30
  - ✅ **Automatic Font Selection** - Uses appropriate fonts per language
16
31
  - ✅ **Proper Text Alignment** - RTL text aligns right, LTR text aligns left
@@ -18,721 +33,213 @@ All existing PDFMake code works unchanged, with automatic RTL support added!
18
33
  - ✅ **Mixed Content Support** - Handles Arabic/Persian/Urdu/English mixed content
19
34
  - ✅ **100% PDFMake Compatible** - Drop-in replacement for PDFMake
20
35
 
21
-
22
36
  ## 🌐 Live Demo
23
37
 
24
38
  👉 [View Live Demo on Netlify](https://pdfmake-rtl.netlify.app)
25
39
 
26
- ## 📦 Installation
27
-
28
- ```bash
29
- npm install @digicole/pdfmake-rtl
30
- ```
40
+ PDF document generation library for server-side and client-side in pure JavaScript.
31
41
 
42
+ Check out [the playground](http://aysnet1.github.io/pdfmake-rtl/playground.html) and [examples](https://github.com/aysnet1/pdfmake-rtl/tree/master/examples).
32
43
 
44
+ ## documentation
33
45
 
34
- ## 🎯 Quick Start NodeJs
46
+ For comprehensive guides, API references, and usage examples, visit the official documentation at [pdfmake.github.io/docs](https://pdfmake.github.io/docs/).
35
47
 
36
- ```javascript
37
- const PdfPrinter = require('@digicole/pdfmake-rtl');
48
+ ### Features
38
49
 
39
- const fonts = {
40
- Roboto: {
41
- normal: './fonts/Roboto-Regular.ttf',
42
- bold: './fonts/Roboto-Medium.ttf',
43
- },
44
- Amiri: {
45
- normal: './fonts/Amiri-Regular.ttf',
46
- bold: './fonts/Amiri-Bold.ttf',
47
- }
48
- };
50
+ #### 🔤 RTL Language Support
51
+
52
+ - **Automatic RTL detection** for Arabic, Persian (Farsi), Urdu, and other RTL scripts
53
+ - **Smart table column reversal** — columns automatically reverse for RTL content
54
+ - **Automatic font selection** — uses Cairo font for Arabic, Persian, and Urdu text
55
+ - **Proper text alignment** — RTL text automatically aligns right, LTR aligns left
56
+ - **List bullet positioning** — bullets and numbers positioned correctly for RTL lists
57
+ - **Mixed content handling** — seamlessly handles Arabic/Persian/Urdu/English in the same document
58
+ - **Unicode script detection** — supports Arabic, Persian, Urdu characters and extensions
59
+
60
+ #### 🗒️ Supported RTL Languages
61
+
62
+ | Language | Script | Auto Font |
63
+ | ----------------- | ------- | --------- |
64
+ | Arabic | العربية | Cairo |
65
+ | Persian (Farsi) | فارسی | Cairo |
66
+ | Urdu | اردو | Cairo |
67
+ | Other RTL scripts | — | Cairo |
68
+
69
+ #### 📄 General Features
70
+
71
+ - line-wrapping,
72
+ - text-alignments (left, right, centered, justified),
73
+ - numbered and bulleted lists (with RTL-aware bullet positioning),
74
+ - tables and columns
75
+ - auto/fixed/star-sized widths,
76
+ - col-spans and row-spans,
77
+ - headers automatically repeated in case of a page-break,
78
+ - **automatic column reversal for RTL content**,
79
+ - images and vector graphics,
80
+ - convenient styling and style inheritance,
81
+ - page headers and footers:
82
+ - static or dynamic content,
83
+ - access to current page number and page count,
84
+ - background-layer,
85
+ - page dimensions and orientations,
86
+ - margins,
87
+ - document sections,
88
+ - custom page breaks,
89
+ - font embedding (Cairo font included for RTL support),
90
+ - support for complex, multi-level (nested) structures,
91
+ - table of contents,
92
+ - helper methods for opening/printing/downloading the generated PDF,
93
+ - setting of PDF metadata (e.g. author, subject).
49
94
 
50
- const printer = new PdfPrinter(fonts);
51
-
52
- const docDefinition = {
53
- // force RTL
54
- // supportRTL:true,
55
- content: [
56
- // English text - automatically aligned left
57
- 'This English text will automatically align left',
58
-
59
- // Arabic text - automatically aligned right
60
- 'هذا النص العربي سيظهر تلقائياً من اليمين إلى اليسار',
61
-
62
- // Arabic table - columns automatically reversed
63
- {
64
- table: {
65
- body: [
66
- ['الاسم الأول', 'الاسم الأخير', 'العمر'],
67
- ['أحمد', 'محمد', '٢٥'],
68
- ['فاطمة', 'علي', '٣٠']
69
- ]
70
- }
71
- }
72
- ]
73
- };
95
+ ## 📦 Installation
74
96
 
75
- const pdfDoc = printer.createPdfKitDocument(docDefinition);
76
- pdfDoc.pipe(fs.createWriteStream('document.pdf'));
77
- pdfDoc.end();
97
+ ```bash
98
+ npm install pdfmake-rtl
78
99
  ```
79
- ## 💻 Client-Side Usage
80
-
81
- ### Browser Integration
82
100
 
83
- Include the RTL-enabled PDFMake in your HTML:
101
+ ## Quick Start Browser (Client-Side)
84
102
 
85
103
  ```html
86
- <!DOCTYPE html>
87
- <html>
88
- <head>
89
- <title>PDFMake RTL Client Example</title>
90
- <script src="https://unpkg.com/@digicole/pdfmake-rtl/build/pdfmake.min.js"></script>
91
- <script src="https://unpkg.com/@digicole/pdfmake-rtl/build/vfs_fonts.js"></script>
92
- </head>
93
- <body>
94
- <script>
95
-
96
- pdfMake.vfs = vfs;
97
- pdfMake.fonts = {
98
-
99
- Nillima: {
100
- normal: 'Nillima.ttf',
101
- bold: 'Nillima.ttf',
102
- italics: 'Nillima.ttf',
103
- bolditalics: 'Nillima.ttf',
104
- },
105
- Roboto: {
106
- normal: 'Roboto-Regular.ttf',
107
- bold: 'Roboto-Medium.ttf',
108
- italics: 'Roboto-Italic.ttf',
109
- bolditalics: 'Roboto-MediumItalic.ttf',
110
- },
111
- };
112
- // Arabic/Persian/Urdu content with automatic RTL detection
113
- const docDefinition = {
114
- // force RTL
115
- // supportRTL:true,
116
- content: [
117
- // English text (auto-detected as LTR)
118
- { text: 'English Title', style: 'header' },
119
-
120
- // Arabic text (auto-detected as RTL)
121
- { text: 'العنوان العربي', style: 'header' },
122
-
123
- // Persian text (auto-detected as RTL)
124
- { text: 'عنوان فارسی', style: 'header' },
125
-
126
- // Urdu text (auto-detected as RTL)
127
- { text: 'اردو عنوان', style: 'header' },
128
-
129
- // Mixed content table (auto-detects direction per cell)
130
- {
131
- table: {
132
- widths: ['*', '*', '*'],
133
- body: [
134
- ['Name', 'الاسم', 'نام'], // Headers
135
- ['Ahmed', 'أحمد', 'احمد'], // Arabic/Persian names
136
- ['Fatima', 'فاطمة', 'فاطمہ'], // Mixed scripts
137
- ['Hassan', 'حسن', 'حسن'] // Common across languages
138
- ]
139
- }
140
- },
141
-
142
- // RTL list (bullets auto-positioned)
143
- {
144
- ul: [
145
- 'Arabic: العنصر الأول',
146
- 'Persian: مورد اول',
147
- 'Urdu: پہلا آئٹم',
148
- 'Mixed: Item واحد'
149
- ]
150
- }
151
- ],
152
-
153
- styles: {
154
- header: {
155
- fontSize: 18,
156
- bold: true,
157
- margin: [0, 0, 0, 10]
158
- }
159
- }
160
- };
161
-
162
- // Generate and download PDF
163
- function createPDF() {
164
- pdfMake.createPdf(docDefinition).download('rtl-document.pdf');
165
- }
166
-
167
- // Or open in new window
168
- function openPDF() {
169
- pdfMake.createPdf(docDefinition).open();
170
- }
171
- </script>
172
-
173
- <button onclick="createPDF()">Download RTL PDF</button>
174
- <button onclick="openPDF()">Open RTL PDF</button>
175
- </body>
176
- </html>
177
- ```
178
-
179
- ### Advanced Client-Side Features
180
-
181
- ```javascript
182
- // Custom font configuration for better RTL support
183
- pdfMake.fonts = {
184
- Roboto: {
185
- normal: 'https://fonts.googleapis.com/css2?family=Roboto',
186
- bold: 'https://fonts.googleapis.com/css2?family=Roboto:wght@700'
187
- },
188
- Amiri: {
189
- normal: 'https://fonts.googleapis.com/css2?family=Amiri',
190
- bold: 'https://fonts.googleapis.com/css2?family=Amiri:wght@700'
191
- },
192
- Vazir: { // Persian font
193
- normal: 'https://fonts.googleapis.com/css2?family=Vazir',
194
- bold: 'https://fonts.googleapis.com/css2?family=Vazir:wght@700'
195
- }
196
- };
197
-
198
- // RTL-aware document with automatic detection
199
- const advancedDoc = {
200
- content: [
201
- // Automatic language detection and appropriate styling
202
- {
203
- text: 'تقرير شهري - گزارش ماهانه - ماہانہ رپورٹ',
204
- style: 'title',
205
- // RTL auto-detected, right-aligned automatically
206
- },
207
-
208
- // Dynamic content with RTL detection
209
- {
210
- columns: [
211
- {
212
- width: '*',
213
- text: [
214
- 'Statistics:\n',
215
- 'المبيعات: ١٢٣٤\n', // Arabic
216
- 'فروش: ۱۲۳۴\n', // Persian
217
- 'فروخت: ۱۲۳۴' // Urdu
218
- ]
219
- },
220
- {
221
- width: '*',
222
- text: [
223
- 'Performance:\n',
224
- 'الأداء: ممتاز\n', // Arabic
225
- 'عملکرد: عالی\n', // Persian
226
- 'کارکردگی: بہترین' // Urdu
227
- ]
228
- }
229
- ]
230
- }
231
- ],
232
-
233
- styles: {
234
- title: {
235
- fontSize: 20,
236
- bold: true,
237
- margin: [0, 0, 0, 20]
238
- // alignment automatically set based on content direction
239
- }
240
- },
241
-
242
- defaultStyle: {
243
- // RTL languages get Amiri/Vazir, LTR gets Roboto automatically
244
- font: 'Roboto'
245
- }
246
- };
247
- ```
248
-
249
- ### React/Vue Integration
250
-
251
- ```javascript
252
- // React component example
253
- import pdfMake from '@digicole/pdfmake-rtl/build/pdfmake';
254
- import pdfFonts from '@digicole/pdfmake-rtl/build/vfs_fonts';
255
-
256
- pdfMake.vfs = pdfFonts;
257
-
258
- const RTLPDFGenerator = () => {
259
- const generateRTLReport = () => {
260
- const docDef = {
261
- content: [
262
- { text: 'تقرير المشروع', style: 'header' }, // Arabic
263
- { text: 'گزارش پروژه', style: 'header' }, // Persian
264
- { text: 'منصوبہ رپورٹ', style: 'header' }, // Urdu
265
-
266
- // Auto-detecting table
267
- {
268
- table: {
269
- body: [
270
- ['المرحلة', 'مرحله', 'مرحلہ', 'Status'],
271
- ['التخطيط', 'طراحی', 'منصوبہ بندی', 'Complete'],
272
- ['التنفيذ', 'اجرا', 'عمل درآمد', 'In Progress'],
273
- ['الاختبار', 'تست', 'جانچ', 'Pending']
274
- ]
275
- }
276
- }
277
- ]
278
- };
279
-
280
- pdfMake.createPdf(docDef).open();
281
- };
282
-
283
- return <button onClick={generateRTLReport}>Generate RTL Report</button>;
104
+ <!-- Load pdfmake-rtl + fonts -->
105
+ <script src="https://unpkg.com/pdfmake-rtl/build/pdfmake.min.js"></script>
106
+ <script src="https://unpkg.com/pdfmake-rtl/build/vfs_fonts.js"></script>
107
+ <!-- <script src="https://unpkg.com/pdfmake-rtl/build/fonts/Cairo.js"></script> -->
108
+
109
+ <script>
110
+ var dd = {
111
+ rtl: true,
112
+ // If Cairo font isn't applied automatically, set `rtl: true` to force RTL mode or add defaultStyle:{font:'Cairo'}
113
+ content: [
114
+ // RTL paragraph — auto-detected, no configuration needed
115
+ { text: "مرحباً بكم في مكتبة pdfmake-rtl", fontSize: 20, bold: true },
116
+ {
117
+ text: "هذه المكتبة تدعم اللغة العربية تلقائياً",
118
+ margin: [0, 0, 0, 15],
119
+ },
120
+
121
+ // RTL table — columns auto-reverse for Arabic content
122
+ {
123
+ table: {
124
+ // rtl:true
125
+ widths: ["*", "*", "*"],
126
+ body: [
127
+ [
128
+ { text: "الراتب", bold: true },
129
+ { text: "القسم", bold: true },
130
+ { text: "الاسم", bold: true },
131
+ ],
132
+ ["5000", "تكنولوجيا", "أحمد محمد"],
133
+ ["6000", "تسويق", "فاطمة علي"],
134
+ ],
135
+ },
136
+ },
137
+
138
+ // Force RTL on any table with rtl: true
139
+ {
140
+ table: {
141
+ rtl: true,
142
+ widths: ["*", "*", "*"],
143
+ body: [
144
+ [
145
+ { text: "Status", bold: true },
146
+ { text: "Name", bold: true },
147
+ { text: "#", bold: true },
148
+ ],
149
+ ["Active", "Ali Hassan", "1"],
150
+ ["Active", "Sara Ahmed", "2"],
151
+ ],
152
+ },
153
+ },
154
+ ],
155
+ };
156
+
157
+ pdfMake.createPdf(dd).open();
158
+ </script>
159
+ ```
160
+
161
+ > 📄 See the full working example: [`examples/simple-rtl-table.html`](examples/simple-rtl-table.html)
162
+
163
+ ## Quick Start — Node.js (Server-Side)
164
+
165
+ ```js
166
+ var pdfmake = require("@digicole/pdfmake-rtl");
167
+
168
+ // Add fonts
169
+ // Cairo is the default font for RTL languages (Arabic, Persian, Urdu)
170
+ // Roboto is the default font for LTR/Latin text
171
+ var Roboto = require("@digicole/pdfmake-rtl/fonts/Roboto");
172
+ pdfmake.addFonts(Roboto);
173
+
174
+ var Cairo = require("@digicole/pdfmake-rtl/fonts/Cairo");
175
+ pdfmake.addFonts(Cairo);
176
+
177
+ var dd = {
178
+ // If Cairo font isn't applied automatically, set `rtl: true` to force RTL mode or add defaultStyle Cairo
179
+ rtl: true, // Forces RTL layout direction for the entire document
180
+ content: [
181
+ { text: "مرحباً بكم في مكتبة pdfmake-rtl", fontSize: 20, bold: true },
182
+ {
183
+ table: {
184
+ widths: ["*", "*", "*"],
185
+ body: [
186
+ [
187
+ { text: "الراتب", bold: true },
188
+ { text: "القسم", bold: true },
189
+ { text: "الاسم", bold: true },
190
+ ],
191
+ ["5000", "تكنولوجيا", "أحمد محمد"],
192
+ ["6000", "تسويق", "فاطمة علي"],
193
+ ],
194
+ },
195
+ },
196
+ ],
284
197
  };
285
- ```
286
- ## 📸 Demo Screenshots
287
-
288
- ### 🖼️ Example 1 – Multilingual Automatically Detected
289
-
290
- ![Multilingual PDF Paragraph Demo](https://i.imgur.com/aIbfbww.jpeg)
291
-
292
- ---
293
-
294
- ## 🌍 Language Support
295
-
296
- ### Automatically Detected Scripts
297
-
298
- | Language | Unicode Range | Status |
299
- |----------|---------------|--------|
300
- | Arabic | U+0600–U+06FF | ✅ |
301
- | Persian (Farsi) | U+06A9–U+06AF, U+06C0–U+06C3 | ✅ |
302
- | Urdu | U+0679, U+067E, U+0686, U+0688, U+0691, U+0698, U+06A9, U+06BA, U+06BB, U+06BE, U+06C1, U+06C3, U+06CC, U+06D2, U+06D3 | ✅ |
303
- | Arabic Supplement | U+0750–U+077F | ✅ |
304
- | Arabic Extended-A | U+08A0–U+08FF | ✅ |
305
- | Arabic Presentation Forms | U+FB50–U+FDFF, U+FE70–U+FEFF | ✅ |
306
- | Persian/Urdu Special Chars | U+200C–U+200D (ZWNJ/ZWJ) | ✅ |
307
-
308
- ## 🎨 Language-Specific Examples
309
-
310
- ### Arabic Document
311
- ```javascript
312
- const arabicDoc = {
313
- content: [
314
- { text: 'تقرير شهري', style: 'title' },
315
- { text: 'إعداد: أحمد محمد', style: 'subtitle' },
316
- {
317
- table: {
318
- widths: ['*', '*', '*'],
319
- body: [
320
- ['الاسم', 'المنصب', 'الراتب'],
321
- ['أحمد علي', 'مطور', '٥٠٠٠'],
322
- ['فاطمة حسن', 'مديرة', '٧٠٠٠']
323
- ]
324
- }
325
- },
326
- {
327
- ul: [
328
- 'النقطة الأولى',
329
- 'النقطة الثانية',
330
- 'النقطة الثالثة'
331
- ]
332
- }
333
- ]
334
- };
335
- ```
336
198
 
337
- ### Long Text Table Example
338
- ```javascript
339
- const longTextTableDoc = {
340
- content: [
341
- { text: 'تقرير مفصل - گزارش تفصیلی - تفصیلی رپورٹ', style: 'title' },
342
-
343
- // Table with long text content - automatic text wrapping and RTL alignment
344
- {
345
- table: {
346
- widths: ['25%', '35%', '40%'],
347
- headerRows: 1,
348
- body: [
349
- // Headers
350
- [
351
- { text: 'القسم\nDepartment\nشعبہ', style: 'tableHeader' },
352
- { text: 'الوصف المفصل\nDetailed Description\nتفصیلی تشریح', style: 'tableHeader' },
353
- { text: 'الملاحظات والتوصيات\nNotes & Recommendations\nنوٹس اور سفارشات', style: 'tableHeader' }
354
- ],
355
-
356
- // Arabic row with long content
357
- [
358
- 'قسم تطوير البرمجيات',
359
- 'هذا القسم مسؤول عن تطوير وصيانة جميع التطبيقات والأنظمة البرمجية المستخدمة في الشركة، بما في ذلك أنظمة إدارة قواعد البيانات وتطبيقات الويب والتطبيقات المحمولة',
360
- 'يُنصح بزيادة عدد المطورين في هذا القسم نظراً للزيادة المتوقعة في المشاريع خلال العام القادم. كما يُفضل الاستثمار في التدريب على التقنيات الحديثة مثل الذكاء الاصطناعي والحوسبة السحابية'
361
- ],
362
-
363
- // Persian row with long content
364
- [
365
- 'بخش توسعه نرم‌افزار',
366
- 'این بخش مسئول توسعه و نگهداری تمام برنامه‌ها و سیستم‌های نرم‌افزاری مورد استفاده در شرکت است، از جمله سیستم‌های مدیریت پایگاه داده، برنامه‌های وب و برنامه‌های موبایل',
367
- 'توصیه می‌شود تعداد توسعه‌دهندگان در این بخش افزایش یابد با توجه به افزایش مورد انتظار پروژه‌ها در سال آینده. همچنین بهتر است روی آموزش تکنولوژی‌های جدید مانند هوش مصنوعی و رایانش ابری سرمایه‌گذاری شود'
368
- ],
369
-
370
- // Urdu row with long content
371
- [
372
- 'سافٹ ویئر ڈیولپمنٹ شعبہ',
373
- 'یہ شعبہ کمپنی میں استعمال ہونے والے تمام ایپلیکیشنز اور سافٹ ویئر سسٹمز کی ترقی اور دیکھ بھال کا ذمہ دار ہے، جن میں ڈیٹا بیس مینجمنٹ سسٹمز، ویب ایپلیکیشنز اور موبائل ایپلیکیشنز شامل ہیں',
374
- 'آئندہ سال متوقع پروجیکٹس میں اضافے کے پیش نظر اس شعبے میں ڈیولپرز کی تعداد بڑھانے کی سفارش کی جاتی ہے۔ نیز جدید ٹیکنالوجیز جیسے مصنوعی ذہانت اور کلاؤڈ کمپیوٹنگ کی تربیت میں سرمایہ کاری کرنا بہتر ہوگا'
375
- ],
376
-
377
- // Mixed languages row
378
- [
379
- 'Quality Assurance\nضمان الجودة\nتضمین کیفیت\nکوالٹی ایشورنس',
380
- 'This department ensures software quality through comprehensive testing. يضمن هذا القسم جودة البرمجيات من خلال الاختبار الشامل. این بخش از طریق تست جامع کیفیت نرم‌افزار را تضمین می‌کند. یہ شعبہ جامع ٹیسٹنگ کے ذریعے سافٹ ویئر کی کوالٹی کو یقینی بناتا ہے۔',
381
- 'Implement automated testing frameworks. تنفيذ إطارات الاختبار التلقائية. چارچوب‌های تست خودکار را پیاده‌سازی کنید. خودکار ٹیسٹنگ فریم ورک کو نافذ کریں۔'
382
- ]
383
- ]
384
- },
385
- layout: {
386
- hLineWidth: function (i, node) {
387
- return (i === 0 || i === node.table.body.length) ? 2 : 1;
388
- },
389
- vLineWidth: function (i, node) {
390
- return (i === 0 || i === node.table.widths.length) ? 2 : 1;
391
- },
392
- hLineColor: function (i, node) {
393
- return (i === 0 || i === node.table.body.length) ? 'black' : 'gray';
394
- },
395
- vLineColor: function (i, node) {
396
- return (i === 0 || i === node.table.widths.length) ? 'black' : 'gray';
397
- }
398
- }
399
- },
400
-
401
- // Performance metrics table with numeric data
402
- {
403
- text: 'مقاييس الأداء - معیارهای عملکرد - کارکردگی کے معیار',
404
- style: 'sectionHeader',
405
- margin: [0, 20, 0, 10]
406
- },
407
- {
408
- table: {
409
- widths: ['*', '*', '*', '*'],
410
- body: [
411
- ['المقياس\nMetric\nمعیار', 'الهدف\nTarget\nہدف', 'الفعلي\nActual\nحقیقی', 'التقييم\nEvaluation\nتشخیص'],
412
- ['نسبة إنجاز المشاريع\nProject Completion Rate\nپروجیکٹ تکمیل کی شرح', '٩٠٪', '٨٥٪', 'جيد - Good - اچھا'],
413
- ['رضا العملاء\nCustomer Satisfaction\nکسٹمر کی اطمینان', '٩٥٪', '٩٨٪', 'ممتاز - Excellent - بہترین'],
414
- ['زمن الاستجابة\nResponse Time\nجوابی وقت', '< ٢ ساعة\n< 2 hours\n< ۲ گھنٹے', '١.٥ ساعة\n1.5 hours\n۱.۵ گھنٹے', 'ممتاز - Excellent - بہترین']
415
- ]
416
- }
417
- }
418
- ],
419
-
420
- styles: {
421
- title: {
422
- fontSize: 22,
423
- bold: true,
424
- margin: [0, 0, 0, 20],
425
- alignment: 'center'
426
- },
427
- sectionHeader: {
428
- fontSize: 16,
429
- bold: true,
430
- color: '#2c3e50'
431
- },
432
- tableHeader: {
433
- bold: true,
434
- fontSize: 12,
435
- color: 'white',
436
- fillColor: '#3498db'
437
- }
438
- },
439
-
440
- defaultStyle: {
441
- fontSize: 10,
442
- lineHeight: 1.3
443
- }
444
- };
445
- ```
446
-
447
- ### Persian (Farsi) Document
448
- ```javascript
449
- const persianDoc = {
450
- content: [
451
- { text: 'گزارش ماهانه', style: 'title' },
452
- { text: 'تهیه کننده: علی احمدی', style: 'subtitle' },
453
- {
454
- table: {
455
- widths: ['*', '*', '*'],
456
- body: [
457
- ['نام', 'سمت', 'حقوق'],
458
- ['علی رضا', 'برنامه نویس', '۵۰۰۰'],
459
- ['فاطمه کریمی', 'مدیر', '۷۰۰۰']
460
- ]
461
- }
462
- },
463
- {
464
- ol: [
465
- 'مورد اول',
466
- 'مورد دوم',
467
- 'مورد سوم'
468
- ]
469
- }
470
- ]
471
- };
199
+ var pdf = pdfmake.createPdf(dd);
200
+ pdf.write("output.pdf").then(() => console.log("PDF created!"));
472
201
  ```
473
202
 
474
- ### Urdu Document
475
- ```javascript
476
- const urduDoc = {
477
- content: [
478
- { text: 'ماہانہ رپورٹ', style: 'title' },
479
- { text: 'تیار کنندہ: احمد علی', style: 'subtitle' },
480
- {
481
- table: {
482
- widths: ['*', '*', '*'],
483
- body: [
484
- ['نام', 'عہدہ', 'تنخواہ'],
485
- ['احمد حسن', 'ڈویلپر', '۵۰۰۰'],
486
- ['فاطمہ خان', 'منیجر', '۷۰۰۰']
487
- ]
488
- }
489
- },
490
- {
491
- ul: [
492
- 'پہلا نکتہ',
493
- 'دوسرا نکتہ',
494
- 'تیسرا نکتہ'
495
- ]
496
- }
497
- ]
498
- };
499
- ```
500
-
501
- ### Mixed Languages Document
502
- ```javascript
503
- const multilingualDoc = {
504
- content: [
505
- // Headers in all languages
506
- { text: 'Project Report - تقرير المشروع - گزارش پروژه - پروجیکٹ رپورٹ', style: 'title' },
507
-
508
- // Multi-language table
509
- {
510
- table: {
511
- widths: ['*', '*', '*', '*'],
512
- body: [
513
- ['English', 'العربية', 'فارسی', 'اردو'],
514
- ['Name', 'الاسم', 'نام', 'نام'],
515
- ['Project', 'المشروع', 'پروژه', 'منصوبہ'],
516
- ['Report', 'التقرير', 'گزارش', 'رپورٹ'],
517
- ['Complete', 'مكتمل', 'کامل', 'مکمل']
518
- ]
519
- }
520
- },
521
-
522
- // Mixed content paragraphs
523
- { text: 'Status: مكتمل - کامل - مکمل (Complete)', margin: [0, 10] },
524
- { text: 'Team: الفريق - تیم - ٹیم (Team Members)', margin: [0, 10] }
525
- ]
526
- };
527
- ```
528
-
529
- ### Advanced Long Text Table with Page Breaks
530
- ```javascript
531
- const advancedLongTableDoc = {
532
- content: [
533
- { text: 'تقرير شامل للمشاريع - جامع پروژه رپورٹ', style: 'mainTitle' },
534
-
535
- // Large table that spans multiple pages with long text content
536
- {
537
- table: {
538
- headerRows: 2,
539
- widths: ['15%', '25%', '30%', '30%'],
540
- body: [
541
- // Main header
542
- [
543
- { text: 'المشروع\nProject\nپروژه', style: 'headerStyle', rowSpan: 2 },
544
- { text: 'التفاصيل الفنية\nTechnical Details\nتکنیکی تفصیلات', style: 'headerStyle', colSpan: 2 },
545
- {},
546
- { text: 'الحالة والملاحظات\nStatus & Notes\nحالت اور نوٹس', style: 'headerStyle', rowSpan: 2 }
547
- ],
548
- // Sub header
549
- [
550
- {},
551
- { text: 'التقنيات المستخدمة\nTechnologies\nٹیکنالوجیز', style: 'subHeaderStyle' },
552
- { text: 'المتطلبات والمواصفات\nRequirements\nضروریات', style: 'subHeaderStyle' },
553
- {}
554
- ],
555
-
556
- // Project 1 - Very long content
557
- [
558
- 'نظام إدارة المحتوى الإلكتروني\n\nContent Management System\n\nمواد کا نظام',
559
- 'تم تطوير هذا النظام باستخدام تقنيات حديثة مثل React.js للواجهة الأمامية و Node.js للخادم الخلفي، مع استخدام قاعدة بيانات MongoDB لتخزين البيانات بكفاءة عالية.\n\nDeveloped using modern technologies including React.js for frontend and Node.js for backend, with MongoDB database for efficient data storage.\n\nجدید ٹیکنالوجیز جیسے React.js فرنٹ اینڈ کے لیے اور Node.js بیک اینڈ کے لیے استعمال کرکے تیار کیا گیا، ڈیٹا کو مؤثر طریقے سے محفوظ کرنے کے لیے MongoDB ڈیٹابیس کا استعمال کیا گیا۔',
560
- 'يجب أن يدعم النظام ما لا يقل عن ١٠٠٠ مستخدم متزامن، مع إمكانية رفع ملفات بحجم يصل إلى ١٠٠ ميجابايت، وتوفير واجهات برمجة تطبيقات RESTful للتكامل مع الأنظمة الأخرى.\n\nSystem must support at least 1000 concurrent users, file uploads up to 100MB, and provide RESTful APIs for integration.\n\nسسٹم کو کم از کم ۱۰۰۰ بیک وقت صارفین کی حمایت کرنی چاہیے، ۱۰۰ میگابائٹ تک فائل اپ لوڈ، اور انٹیگریشن کے لیے RESTful APIs فراہم کرنا چاہیے۔',
561
- 'المشروع مكتمل بنسبة ٩٥٪ ويتوقع إطلاقه في نهاية هذا الشهر. تم اجتياز جميع اختبارات الأداء والأمان بنجاح.\n\nProject is 95% complete and expected to launch by end of month. All performance and security tests passed successfully.\n\nپروجیکٹ ۹۵٪ مکمل ہے اور اس مہینے کے آخر تک لانچ ہونے کی توقع ہے۔ تمام کارکردگی اور سیکیورٹی ٹیسٹ کامیابی سے پاس ہوئے۔'
562
- ],
563
-
564
- // Project 2
565
- [
566
- 'تطبيق التجارة الإلكترونية\n\nE-commerce Application\n\nای کامرس ایپلیکیشن',
567
- 'يستخدم التطبيق تقنيات متقدمة مثل Vue.js و Express.js مع قاعدة بيانات PostgreSQL وخدمات الدفع الآمنة مثل Stripe و PayPal.\n\nApplication uses advanced technologies like Vue.js and Express.js with PostgreSQL database and secure payment services like Stripe and PayPal.\n\nایپلیکیشن جدید ٹیکنالوجیز جیسے Vue.js اور Express.js استعمال کرتی ہے PostgreSQL ڈیٹابیس اور محفوظ پیمنٹ سروسز جیسے Stripe اور PayPal کے ساتھ۔',
568
- 'التطبيق يحتاج إلى دعم عدة عملات ولغات، مع نظام إدارة المخزون المتقدم وتتبع الطلبات في الوقت الفعلي، بالإضافة إلى تحليلات مفصلة للمبيعات.\n\nApplication needs multi-currency and multi-language support, advanced inventory management, real-time order tracking, and detailed sales analytics.\n\nایپلیکیشن کو کئی کرنسیوں اور زبانوں کی حمایت، ایڈوانسڈ انوینٹری منیجمنٹ، ریئل ٹائم آرڈر ٹریکنگ، اور تفصیلی سیلز ایڈالٹکس کی ضرورت ہے۔',
569
- 'التطوير في المرحلة النهائية مع اكتمال ٨٥٪ من الوظائف الأساسية. يجري حالياً اختبار نظام الدفع والأمان.\n\nDevelopment in final phase with 85% of core features complete. Currently testing payment system and security.\n\nبنیادی فیچرز کے ۸۵٪ مکمل ہونے کے ساتھ ڈیولپمنٹ حتمی مرحلے میں ہے۔ فی الوقت پیمنٹ سسٹم اور سیکیورٹی کو ٹیسٹ کیا جا رہا ہے۔'
570
- ],
571
-
572
- // Project 3
573
- [
574
- 'نظام إدارة الموارد البشرية\n\nHR Management System\n\nHR منیجمنٹ سسٹم',
575
- 'النظام مبني على تقنيات السحابة مع استخدام Docker للنشر و Kubernetes للتوسع التلقائي، مع قاعدة بيانات MySQL المحسنة للأداء العالي.\n\nSystem built on cloud technologies using Docker for deployment and Kubernetes for auto-scaling, with optimized MySQL database for high performance.\n\nسسٹم کلاؤڈ ٹیکنالوجیز پر بنایا گیا ہے Docker کا استعمال کرتے ہوئے deployment کے لیے اور Kubernetes auto-scaling کے لیے، high performance کے لیے optimized MySQL database کے ساتھ۔',
576
- 'يجب أن يتضمن النظام إدارة الحضور والانصراف، حساب الرواتب التلقائي، تقييم الأداء، وإدارة الإجازات مع التكامل مع أنظمة المحاسبة الموجودة.\n\nSystem must include attendance management, automatic payroll calculation, performance evaluation, and leave management with integration to existing accounting systems.\n\nسسٹم میں حاضری کا نظام، خودکار تنخواہ کیلکولیشن، کارکردگی کی تشخیص، اور چھٹی کا نظام شامل ہونا چاہیے موجودہ اکاؤنٹنگ سسٹمز کے ساتھ انٹیگریشن کے ساتھ۔',
577
- 'المشروع في مرحلة التطوير المتوسطة مع اكتمال ٦٠٪ من المتطلبات. تم إنهاء تصميم قاعدة البيانات وواجهات المستخدم.\n\nProject in middle development phase with 60% of requirements complete. Database design and user interfaces completed.\n\nپروجیکٹ درمیانی ڈیولپمنٹ مرحلے میں ہے ۶۰٪ ضروریات مکمل کے ساتھ۔ ڈیٹابیس ڈیزائن اور یوزر انٹرفیسز مکمل۔'
578
- ]
579
- ]
580
- },
581
- layout: {
582
- hLineWidth: function (i, node) {
583
- if (i === 0 || i === node.table.body.length) return 2;
584
- if (i === 2) return 1.5; // After header
585
- return 0.5;
586
- },
587
- vLineWidth: function (i, node) {
588
- return (i === 0 || i === node.table.widths.length) ? 2 : 1;
589
- },
590
- hLineColor: function (i, node) {
591
- return (i === 0 || i === node.table.body.length) ? '#2c3e50' : '#bdc3c7';
592
- },
593
- vLineColor: function (i, node) {
594
- return (i === 0 || i === node.table.widths.length) ? '#2c3e50' : '#bdc3c7';
595
- },
596
- paddingLeft: function(i, node) { return 8; },
597
- paddingRight: function(i, node) { return 8; },
598
- paddingTop: function(i, node) { return 6; },
599
- paddingBottom: function(i, node) { return 6; }
600
- }
601
- }
602
- ],
603
-
604
- styles: {
605
- mainTitle: {
606
- fontSize: 24,
607
- bold: true,
608
- margin: [0, 0, 0, 30],
609
- alignment: 'center',
610
- color: '#2c3e50'
611
- },
612
- headerStyle: {
613
- bold: true,
614
- fontSize: 12,
615
- color: 'white',
616
- fillColor: '#3498db',
617
- alignment: 'center'
618
- },
619
- subHeaderStyle: {
620
- bold: true,
621
- fontSize: 10,
622
- color: 'white',
623
- fillColor: '#5dade2',
624
- alignment: 'center'
625
- }
626
- },
627
-
628
- defaultStyle: {
629
- fontSize: 9,
630
- lineHeight: 1.4
631
- },
632
-
633
- pageMargins: [40, 60, 40, 60]
634
- };
635
- ```
636
-
637
-
638
-
639
- ### React/Vue Integration
640
-
641
- ```javascript
642
- // React component example
643
- import pdfMake from '@digicole/pdfmake-rtl/build/pdfmake';
644
- import pdfFonts from '@digicole/pdfmake-rtl/build/vfs_fonts';
645
-
646
- pdfMake.vfs = pdfFonts;
647
-
648
- const RTLPDFGenerator = () => {
649
- const generateRTLReport = () => {
650
- const docDef = {
651
- content: [
652
- { text: 'تقرير المشروع', style: 'header' }, // Arabic
653
- { text: 'گزارش پروژه', style: 'header' }, // Persian
654
- { text: 'منصوبہ رپورٹ', style: 'header' }, // Urdu
655
-
656
- // Auto-detecting table
657
- {
658
- table: {
659
- body: [
660
- ['المرحلة', 'مرحله', 'مرحلہ', 'Status'],
661
- ['التخطيط', 'طراحی', 'منصوبہ بندی', 'Complete'],
662
- ['التنفيذ', 'اجرا', 'عمل درآمد', 'In Progress'],
663
- ['الاختبار', 'تست', 'جانچ', 'Pending']
664
- ]
665
- }
666
- }
667
- ]
668
- };
669
-
670
- pdfMake.createPdf(docDef).open();
671
- };
672
-
673
- return <button onClick={generateRTLReport}>Generate RTL Report</button>;
674
- };
675
- ```
676
-
677
-
678
- PDF document generation library for server-side and client-side usage in pure JavaScript.
679
-
680
-
681
- ### Features
682
-
683
- * line-wrapping,
684
- * text-alignments (left, right, centered, justified),
685
- * numbered and bulleted lists,
686
- * tables and columns
687
- * auto/fixed/star-sized widths,
688
- * col-spans and row-spans,
689
- * headers automatically repeated in case of a page-break,
690
- * images and vector graphics,
691
- * convenient styling and style inheritance,
692
- * page headers and footers:
693
- * static or dynamic content,
694
- * access to current page number and page count,
695
- * background-layer,
696
- * page dimensions and orientations,
697
- * margins,
698
- * custom page breaks,
699
- * font embedding,
700
- * support for complex, multi-level (nested) structures,
701
- * table of contents,
702
- * helper methods for opening/printing/downloading the generated PDF,
703
- * setting of PDF metadata (e.g. author, subject).
704
-
705
203
  ## Documentation
706
204
 
707
- Documentation URL: https://pdfmake.github.io/docs/
205
+ **Documentation URL: https://pdfmake-rtl.github.io/docs/**
206
+
207
+ Source of documentation: https://github.com/pdfmake-rtl/docs **Improvements are welcome!**
708
208
 
709
- ## Building from sources version 0.2.x
209
+ ## Building from sources
710
210
 
711
211
  using npm:
212
+
712
213
  ```
713
- git clone --branch 0.2 https://github.com/bpampuch/pdfmake.git
714
- cd pdfmake
214
+ git clone https://github.com/aysnet1/pdfmake-rtl.git
215
+ cd pdfmake-rtl
715
216
  npm install
716
217
  npm run build
717
218
  ```
718
219
 
719
220
  using yarn:
221
+
720
222
  ```
721
- git clone --branch 0.2 https://github.com/bpampuch/pdfmake.git
722
- cd pdfmake
223
+ git clone https://github.com/aysnet1/pdfmake-rtl.git
224
+ cd pdfmake-rtl
723
225
  yarn
724
226
  yarn run build
725
227
  ```
726
228
 
727
229
  ## License
230
+
728
231
  MIT
729
232
 
730
- ## Authors pdfmake-rtl
731
- * [@aysnet1](httpss://github.com/aysnet1)
233
+ ## Credits
234
+
235
+ ### pdfmake-rtl
236
+
237
+ - [@aysnet1](https://github.com/aysnet1) — Creator & Maintainer
238
+
239
+ ### pdfmake (Original Library)
732
240
 
733
- ## Authors pdfmake
734
- * [@bpampuch](https://github.com/bpampuch) (founder)
735
- * [@liborm85](https://github.com/liborm85)
241
+ - [@bpampuch](https://github.com/bpampuch) — Founder
242
+ - [@liborm85](https://github.com/liborm85) — Maintainer
736
243
 
737
244
  pdfmake is based on a truly amazing library [pdfkit](https://github.com/devongovett/pdfkit) (credits to [@devongovett](https://github.com/devongovett)).
738
245