foliojs / pdfkit

A JavaScript PDF generation library for Node and the browser

Home Page:http://pdfkit.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

RTL Direction and justify aligment

baravak opened this issue · comments

Bug Report

When we want to have right-to-left text, such as Persian or Arabic, and the features are set to rtla or rtlm, and we want to set the align to justify, the alignment is applied from the left side. It seems that there is a need for an additional setting to adjust the text direction as well.

Code sample

import { createWriteStream } from "fs";
import PDFDocument from "pdfkit";

// Create a document
const doc = new PDFDocument({ size: "A4" });
doc.page.margins = { top: 100, bottom: 100, left: 100, right: 100 };
const fonts = {
    regular: "./fonts/DanaFaNum-Regular.ttf",
};

const styles = {
    normal: doc.font(fonts.regular).fontSize(15),
};

doc.pipe(createWriteStream("output.pdf"));

const text =
    "این یک متن فارسی است که ما می‌خواهیم بدانیم آیا این کتابخانه می‌تواند این متن را ساپورت کند یا خیر؟ به عبارت دیگر هیچ زبان برنامه‌نویسی و کتاب‌خانه درستی در دنیا وجود ندارد که از یک متن فارسی یا راست به چپ پشتیبانی کند!";

styles.normal.text(text, {
    features: ["rtla"],
    align: "justify",
});

styles.normal.text(text, {
    features: ["rtla"],
    align: "right",
});

doc.end();

Your environment

  • pdfkit version:0.13.0
  • Node version:v18.16.0
  • Browser version (if applicable):
  • Operating System:ubuntu 22
    image