question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Registering OTF fonts doesn't work

See original GitHub issue

Test

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: Got PDF with fonts not registered

Expected result

Font embedded. Expected result, PDF with Montserrat Bold 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:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
devongovettcommented, Jan 28, 2019
1reaction
blikblumcommented, Jan 7, 2019

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found