I'm using pdfkit package for node js application to generate PDFs, but I faced a problem when I attempted to generate Arabic text. It always reverses the numbers in Arabic texts.
if I want to write: ساڵی 1992 (The year 1992), it always changes to (ساڵی ٢٩٩١), This issue persists even when I use Unicode custom fonts.
This is an example in image:
Here are my codes:
function generatePDFForRuleAndRegulation(data) {
const fileNamePDF = `${data.name}.pdf`;
const doc = new PDFDocument();
// Pipe the PDF document to a writable stream (file in this case)
const stream = fs.createWriteStream(fileNamePDF);
doc.pipe(stream);
doc
.font(`${path.join(__dirname, "../../assets/fonts/NRT-Reg.ttf")}`)
.fontSize(12)
.text(`${data.name}`, {
align: "center",
});
doc.moveDown(); // Move cursor down
doc
.font(`${path.join(__dirname, "../../assets/fonts/Rabar_021.ttf")}`)
.fontSize(10)
.text(data.text, { align: "right", features: ["rtla"] });
// Finalize the PDF document
doc.end();
// Inform when the file has been created
stream.on("finish", () => {
console.log(`PDF created: ${fileNamePDF}`);
});
}
Is there any solution or workaround you can suggest? Alternatively, do you know of another package to generate PDFs that also supports Arabic fonts?

Finally, I used custom RTL instead of pdfkit plugin.