Skip to content

Why are devanagari characters rendered differently from pdfkit? #164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
brandoncc opened this issue Apr 18, 2022 · 0 comments
Open

Why are devanagari characters rendered differently from pdfkit? #164

brandoncc opened this issue Apr 18, 2022 · 0 comments

Comments

@brandoncc
Copy link

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:

  • svg_content.svg
<svg viewBox="0 0 5500 5500" version="1.1" xmlns="http://www.w3.org/2000/svg">
  <text>
    <tspan x="650" y="-300" textLength="402.4" fill="#333333" style="font-size:232.19814241486068px;font-family:martel-devanagari;">
      हैप्पी
    </tspan>
  </text>
</svg>
  • text_content.txt
हैप्पी
  • pdfkit.js
const PDFDocument = require('pdfkit');
const SVGtoPDF = require('svg-to-pdfkit');
const fs = require('fs');

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:

image

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant