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.

Unable to import Google fonts locally

See original GitHub issue

Describe the bug I basically downloaded the font family Inter and supposedly registered it with the following code:

Font.register({
  family: 'Inter',
  fonts: [
    { src: '../../../fonts/static/Inter-Bold.ttf', fontWeight: 700 },
    { src: '../../../fonts/static/Inter-Light.ttf', fontWeight: 300 },
    { src: '../../../fonts/static/Inter-Medium.ttf', fontWeight: 500 },
    { src: '../../../fonts/static/Inter-Regular.ttf', fontWeight: 400 },
  ],
});

However I get an Error: Unknown font format in the browser and the file won’t download at all. When I somehow manage to get past this bug all the characters show up as gibberish. I’ve already troubleshooted it in past issues and importing it as modules didn’t work as well. Also, the links from Google apparently don’t apply to the src string, since they only provide <link> tags or @import css statements only…

To Reproduce Then I call the font family in my root container for the PDF file const styles = StyleSheet.create({ container: { margin: ‘5px’, fontFamily: ‘Inter’, }, });

Expected behavior The PDF downloads with the fonts applied.

Screenshots image

Desktop (please complete the following information):

  • OS: Windows 10
  • Browser: Edge
  • React-pdf version: 2

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
mateusmlocommented, Apr 15, 2021

Any updates on this? I’m still unable to import fonts and have no clue how to get around this problem 😦

1reaction
diegomuracommented, May 3, 2021

Got fixed in the commit above. See the before and after using the FiraSans font

Before: a75847b2-8e99-4907-b892-9c9c2a3e948b.pdf

After: 0458a0c9-6dcd-46c0-b8e4-960755a5b213.pdf

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use google fonts locally instead of importing in angular ...
2 step solution. Step - 1 : Download the fonts and save them inside assets folder. Save the ttf/otf file inside the assets...
Read more >
How to Host Google Fonts Locally? Pros, Cons & Why is it not ...
Does hosting Google Fonts locally give any performance improvement? Here we compare both the methods with its pros, cons, and speed tests.
Read more >
Troubleshooting | Google Fonts
By default the NoScript plugin disables @font-face rules. Solution. Open the NoScript Options, go to the Embeddings tab and uncheck: Forbid @font-face. Web ......
Read more >
How to Use Google Fonts and Custom Fonts in Jotform
Open the Form Designer panel in Form Builder. Go to the Styles tab. Paste your Google Fonts import code in the Inject Custom...
Read more >
Installing & managing fonts—including variable fonts
(If you can't move fonts there, use C: \Users\Username\AppData\Local\Microsoft\Windows\Fonts\ to install fonts that can only be accessed by your own ...
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