Trying to register and then use an OpenType font:
const fs = require('fs');
const PDFDocument = require('pdfkit');
const doc = new PDFDocument({ layout: 'landscape' });
const stream = fs.createWriteStream('out.pdf');
// Register the font family
// OTF fonts don't work, TTF does!
doc.registerFont('Montserrat Bold', 'fonts/v5/Montserrat-Bold.otf');
doc
.font('Montserrat Bold')
.text('This is a test of the emergency broadcast signal.');
doc.pipe(stream);
doc.end();
The font didn't register. out.pdf rendered in Chrome or Firefox looks like this:

Font embedded.

It works with TTF. This uses Montserrat Bold v5.001 OTF but I've tried other versions of Montserrat as well as other OpenType fonts. I couldn't get any .otf to work.
Using directly doesn't work either:
doc
.font('fonts/v5/Montserrat-Bold.otf') // Doesn't work
.text('This is a test of the emergency broadcast signal.');
Also tried to check in fontkit – no errors there.
fontkit.openSync('fonts/v5/Montserrat-Bold.otf');
Same issue here. can't use otf fonts
Can you use ttf ? I found these work
yep, ttf fonts have no problems, but otf is not working... Cavertion otf to ttf doesn't work form me.
Any news on this one? I'm having a similar issue. In my case OTF fonts don't show up at all.
I cannot reproduce the issue with master version. Probably fixed in the mean time.
I used the font from https://www.fontsquirrel.com/fonts/list/popular. The linked font gives a Unknown font format error
I tried the Montserrat-Bold.otf font in master yesterday. I replaced palatino with it in demo/test.js. The resulting pdf does work in Acrobat, but it fails in both Chrome/Mac and Safari. In Chrome, it falls back to a san-serif font instead of Montserrat. In Safari or Mac Preview, it shows the wrong glyphs - mostly punctuation.
Should be fixed by https://github.com/foliojs/fontkit/commit/1a2a572b09ced7d2332f1bac1a66acfe960ecdb3 in the fontkit v1.7.8.
V0.9.0 fixes the issue for me, thank you!
This also fixed all the problems i had - both viewing in non-Acrobat viewers and some fonts crashing in font kit. Thanks!
Most helpful comment
Should be fixed by https://github.com/foliojs/fontkit/commit/1a2a572b09ced7d2332f1bac1a66acfe960ecdb3 in the fontkit v1.7.8.