Skip to content

RTL Direction and justify aligment #1447

@baravak

Description

@baravak

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions