Custom font not working
See original GitHub issueI am using the latest version of jsPDF, and trying to use a custom font from Google but it does not work.
I import the font here (the one I’m trying to use is Inconsolata).
<link href="https://fonts.googleapis.com/css?family=Source+Serif+Pro|Inconsolata" rel="stylesheet">
I try to add it with this code and it does show up in the output from getFontList, but the PDF doesn’t use that font.
doc.addFont('Inconsolata','Inconsolata','regular'); console.log(doc.getFontList()); doc.setFont('Inconsolata');
In addition, I get the following error message on the console (which does not appear if I go back to an old version of jsPDF):
jspdf.min.js:102 Uncaught TypeError: Cannot set property 'adler32cs' of undefined at t (jspdf.min.js:102) at jspdf.min.js:102 at jspdf.min.js:1 at jspdf.min.js:1 t @ jspdf.min.js:102 (anonymous) @ jspdf.min.js:102 (anonymous) @ jspdf.min.js:1 (anonymous) @ jspdf.min.js:1
Issue Analytics
- State:
- Created 5 years ago
- Comments:23 (2 by maintainers)
Top GitHub Comments
I can’t get this to work with the font I want to use, which is Inconsolata from Google Fonts. I encoded it using this site: https://www.giftofspeed.com/base64-encoder/.
I modified the demoUsingTTFFont function to use that font, shown below.
Attached is the PDF that I got. I tried a couple of other fonts and got an empty PDF. So what is the problem here? test.pdf
` function demoUsingTTFFont() { var Inconsolata=“Removed by Aras” var doc = new jsPDF();
} `
Currently none. But with 1.4.0 we will have ttf support. But they have to be base64 encoded etc…