6

i'm using pdfkit with nodejs to generate dynamically PDF files. the generation works fine but i have a problem displaying arabic characters even if i setup a font that support arabic.

The letters are rendered correctly, but the words are displayed character by character :(

here's my code

doc = new PDFDocument;
doc.pipe(fs.createWriteStream('output.pdf'));
var str = "فصل الربيع الزهور \n#nature #payesage #fleurs #plantes #vert #espace #temara #rabat #maroc #WeekEnd #balade #instamoment #instalife #instamaroc #photographie #macro #peace";
doc.font('resources/HelveticaNeueLTArabic-Roman.ttf').text(str);

Any thoughts or suggestions will be great.

ahai
  • 61
  • 2
  • Just found out they are switching to **fontkit** for their font engine. Which will bring better support for Arabic languages. – Sayam Qazi Aug 12 '17 at 11:06

1 Answers1

1

Use Amiri font , it supports arabic font

const customFontRegular = fs.readFileSync(`./amiri/Amiri-Regular.ttf`);
const customFontBold = fs.readFileSync(`./amiri/Amiri-Bold.ttf`);

pdfDoc.registerFont(`Amiri-Regular`, customFontRegular);
pdfDoc.registerFont(`Amiri-Bold`, customFontBold);

And it can be used as

pdfDoc.font('Amiri-Regular').text("Hello world");
Adarsh ap
  • 41
  • 3