@digicole/pdfmake-rtl

中文文档
2.1.2发布于 2026/02/11MITCommonJS近 30 天下载 3432

Enhanced PDFMake with comprehensive RTL (Arabic/Persian/Urdu) support - Production ready package

原始使用文档
文档目录13 节
  1. 🚀 Key Features
  2. 🌐 Live Demo
  3. documentation
  4. Features
  5. 📦 Installation
  6. ⚡ Quick Start — Browser (Client-Side)
  7. ⚡ Quick Start — Node.js (Server-Side)
  8. Documentation
  9. Building from sources
  10. License
  11. Credits
  12. pdfmake-rtl
  13. pdfmake (Original Library)

pdfmake-RTL Node.js CI GitHub npm

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!

⚠️ Important: This package has moved to a new npm scope. Please use pdfmake-rtl going forward.

npm install pdfmake-rtl

🚀 Key Features

  • ✅ Automatic RTL Detection - No need to set rtl flags
  • ✅ 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

👉 View Live Demo on Netlify

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

LanguageScriptAuto 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

⚡ Quick Start — Browser (Client-Side)

<!-- 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!"));

Documentation

Documentation URL: https://pdfmake-rtl.github.io/docs/**

Source of documentation: https://github.com/pdfmake-rtl/docs Improvements are welcome!

Building from sources

using npm:

git clone https://github.com/aysnet1/pdfmake-rtl.git
cd pdfmake-rtl
npm install
npm run build

using yarn:

git clone https://github.com/aysnet1/pdfmake-rtl.git
cd pdfmake-rtl
yarn
yarn run build

License

MIT

Credits

pdfmake-rtl

pdfmake (Original Library)

pdfmake is based on a truly amazing library pdfkit (credits to @devongovett).

Thanks to all contributors.

版本与发布记录

@digicole/pdfmake-rtl 共发布 6 个版本,首次发布于 2025/08/05;过去 12 个月发布了 3 个版本。

版本发布日期距今
2.1.2latest2026/02/119 个月前
2.1.12026/02/099 个月前
2.1.02026/02/099 个月前
1.2.02025/08/051.3 年前
1.1.02025/08/051.3 年前
1.0.02025/08/051.3 年前

关于 @digicole/pdfmake-rtl 的常见问题

@digicole/pdfmake-rtl 是什么?

Enhanced PDFMake with comprehensive RTL (Arabic/Persian/Urdu) support - Production ready package

如何安装 @digicole/pdfmake-rtl?

在项目目录运行 npm install @digicole/pdfmake-rtl,或使用 pnpm add / yarn add / bun add。

@digicole/pdfmake-rtl 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/digicole__pdfmake-rtl 是否存在。

@digicole/pdfmake-rtl 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@digicole/pdfmake-rtl 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@digicole/pdfmake-rtl 可以商用吗?

@digicole/pdfmake-rtl 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@digicole/pdfmake-rtl 的下载量有多少?

根据 npm 官方下载统计,@digicole/pdfmake-rtl 在 2026/10/12 – 2026/11/10 这 30 天内被下载 3,432 次,日均约 114 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@digicole/pdfmake-rtl 还在维护吗?

最新版本 2.1.2 发布于 2026/02/11(9 个月前);至今共发布 6 个版本,其中过去 12 个月发布了 3 个;首次发布于 2025/08/05。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。