diegomura / react-pdf

📄 Create PDF files using React
https://react-pdf.org
MIT License
14.22k stars 1.11k forks source link

Multiple fonts not working #2709

Closed dhwaj1902 closed 1 month ago

dhwaj1902 commented 1 month ago

Describe the bug I want to register multiple fonts in react-pdf, but blank screen is coming. Only Roboto font is working while creating the pdf.

image

To Reproduce Steps to reproduce the behavior including code snippet (if applies): Using the code: Font.register({ family: 'Lato', fonts: [ { src: '/font/Lato-Regular.ttf', fontWeight: 400, }, { src: '/font/Lato-Italic.ttf', fontStyle: 'italic', }, { src: '/font/Lato-Bold-Italic.ttf', fontWeight: 500, fontStyle: 'italic', }, { src: '/font/Lato-Bold.ttf', fontWeight: 600, }, { src: '/font/Lato-Bold.ttf', fontWeight: 700, }, { src: '/font/Lato-Bold.ttf', fontWeight: 800, }, ], });

Font.register({ family: 'Roboto', fonts: [ { src: '/font/Roboto-Regular.ttf', fontWeight: 400, }, ... same ], });

Font.register({ family: 'Inter', fonts: [ { src: '/font/Inter-Regular.ttf', fontWeight: 400, }, ... same ], });

Expected behavior If used any of the above registered fonts in the body font-family, then the font should come.

Desktop (please complete the following information):

guillaumeklaus commented 1 month ago

I had the same issue and solved it with this : https://github.com/diegomura/react-pdf/issues/2675#issuecomment-1999002409

dhwaj1902 commented 1 month ago

Thanks a lot that works for me!