alafr / SVG-to-PDFKit

Insert SVG into a PDF document created with PDFKit
MIT License
397 stars 111 forks source link

Why are devanagari characters rendered differently from pdfkit? #164

Open brandoncc opened 2 years ago

brandoncc commented 2 years ago

Hello,

Thank you for this awesome project!

I am having trouble printing devanagari characters, and I'm not sure why. I have created an example using the Martel devanagari font from Google Fonts using the following files:

PDFDocument.prototype.addSVG = function(svg, x, y, options) { return SVGtoPDF(this, svg, x, y, options), this; };

const doc = new PDFDocument(); const data = fs.readFileSync('svg_content.svg', 'utf8'); const data2 = fs.readFileSync('text_content.txt', 'utf8');

doc.pipe(fs.createWriteStream('output.pdf'));

doc.registerFont('martel-devanagari', 'assets/fonts/martel-devanagari/Martel-Regular.ttf');

doc.addSVG(data, 0, 0);

doc .font('assets/fonts/martel-devanagari/Martel-Regular.ttf') .fontSize(25) .text(data2) .text('हैप्पी');

doc.end();



The content comes out like this:

<img width="1101" alt="image" src="https://user-images.githubusercontent.com/543973/163757601-25c6e1b4-45e3-4baf-aaa3-0fc41ee1c287.png">

Something is causing the content added using this library to be different, but I don't know what it is.

Any assistance pointing me in the right direction would be very much appreciated!