Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate Arabic content with PDFKit & nodeJS

Tags:

node.js

pdfkit

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.

like image 250
ahai Avatar asked May 14 '15 23:05

ahai


1 Answers

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");
like image 53
Adarsh ap Avatar answered Sep 30 '22 16:09

Adarsh ap