Can anyone say how to add custom font with @react-pdf/pdfkit
in react.js?
I tried to use doc.registerFont(path, font_family)
But its showing an error like Unhandled Rejection (Error): fontkit.openSync unavailable for browser build
Can anyone help me? I dont want to render the pdf. Instead I am trying to create and download it. So I cant use react-pdf/renderer
. Thats why I used react-pdf/pdfkit
import FontUbuntuRegular from './styles/pdfFonts/ubuntuRegular.ttf';
import FontUbuntuItalic from '.7styles/pdfFonts/ubuntuItalic.ttf';
import FontUbuntu700 from './styles/pdfFonts/ubuntu700.ttf';
Font.register({
family: 'Ubuntu',
fonts: [
{
src: FontUbuntuRegular,
},
{
src: FontUbuntuItalic,
fontWeight: 'bold',
},
{
src: FontUbuntu700,
fontWeight: 'normal',
fontStyle: 'italic',
},
],
});
2. (RECOMMENDED) EASY, and simple, NO webpack configuration.
I found another way to add the src, it was to look for the Webfont.
Font.register({
family: 'Ubuntu',
fonts: [
{
src: 'https://fonts.gstatic.com/s/questrial/v13/QdVUSTchPBm7nuUeVf7EuStkm20oJA.ttf',
},
{
src: 'https://fonts.gstatic.com/s/questrial/v13/QdVUSTchPBm7nuUeVf7EuStkm20oJA.ttf',
fontWeight: 'bold',
},
{
src: 'https://fonts.gstatic.com/s/questrial/v13/QdVUSTchPBm7nuUeVf7EuStkm20oJA.ttf',
fontWeight: 'normal',
fontStyle: 'italic',
},
],
});