react-pdf: Unable to load local font file with Font.register in Next.js
OS: Windows 11 React-pdf version: 3.1.6
Description: Hello, I’ve been trying to register a font for the document from the local file system (since I’m using Nex.js). What i’ve noticed is that if I use the following, the document is never generated
Font.register({ family: "Helvetica Neue", fonts: [{ src: "/public/fonts/helveticaNeue-std.woff2" }], });
I need to use local font because Helvetica font is not on google fonts, but it doesn’t read the from the local Could you give me the solution for this?
Thank you
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 16
Though this is closed, let me just leave this here incase someone needs it. I managed to make it work through trial and error by registering like this:
I have my fonts on
$root/publicdirectory. Using relative path.../.../public/font/font-filedidn’t work for me. probably related to nextjs’s webpack config. After figuring out the solution, I saw this documentation from next.js, pointing out how to access public files.Hi,
Is there any update?
any update ?
@
This works for me, i moved my fonts file from app to public and directly use it on the register function like this:
Font.register({ family: 'Calibri', format: 'truetype', src: "/fonts/calibri.ttf", });Still having an issue with this.
In NextJS, I can’t do
To load a local font, the doc recommends doing
However, I am not able to use
fontin React-pdf’sFont.register()like thisIs there any way to make NextJS and React-PDF work together?
@leonace924 remove
publicfrom the font path