Registering OTF fonts doesn't work
See original GitHub issueTest
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();
Result
The font didn’t register. out.pdf rendered in Chrome or Firefox looks like this:
Expected result
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');
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:9 (2 by maintainers)
Top Results From Across the Web
What to do when Windows won't allow some fonts to install.
Start by clicking on the start button, then on settings, then on personalization and then on fonts. In the window that appears, drag...
Read more >OTF font does not work, but ttf does
I have 2 fonts in same directory: myfont.otf and testfont.ttf, but setting otf font does not work, and ttf does.
Read more >Troubleshooting Installed Fonts That Won't Work
Easiest fix: Download and reinstall the correct version of the file, making sure the font is compatible with your operating system.
Read more >Why won't new purchased OTF fonts install in Catalina?
Any thoughts? Masrop wrote: No matter how I try, I cannot install them. Just drag/drop them into Home/Library/Fonts and restart and see if...
Read more >Fonts Not Displayed When Installing New Fonts
Symptoms. When you add new fonts by clicking Install New Font in the Fonts tool in Control Panel, no fonts may be displayed....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Should be fixed by https://github.com/foliojs/fontkit/commit/1a2a572b09ced7d2332f1bac1a66acfe960ecdb3 in the fontkit v1.7.8.
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