Sunday, 16 May 2021

Align (Justify) Arabic text in jsPDF

I am using npm jspdf 2.3.1 in my react application.

Every thing is working fine. I want to justify the text but the starting point should be "right".

const [state, setState] = useState({
doc: new jsPDF(),
});

const myPdf = ( ) => {
state.doc.addFileToVFS("MyFont.ttf", myFont); // Arabic Font
state.doc.addFont("MyFont.ttf", "MyFont", "normal");

 state.doc.text(
  "لوريم إيبسوم هو ببساطة نص شكلي (بمعنى أن الغاية هي الشكل وليس",
  190,
  10,
  "right"
);

  state.doc.save();
}

What I tried was like this

state.doc.text(
    "لوريم إيبسوم هو ببساطة نص شكلي (بمعنى أن الغاية هي الشكل وليس",
    190, //it prints left to right
    10,
    { maxWidth: 250, align: "justify" } //it's not justifying the text
);

Am I doing it wrong or do I need to use a plugin? Can I keep both "right" and "justify", if yes, how?



from Align (Justify) Arabic text in jsPDF

No comments:

Post a Comment