Knowledge Seeker
Knowledge Seeker

Reputation: 566

Styles in react-pdf showing abnormal behaviour

I'm trying to use italic styling in react-pdf.

Everything works well until I use font-style: italic;.

Is there another way style text as Italic in react-pdf ?

const Italic = styled.Text`
  font-size: 12px;
  lineheight: 20px;
  text-align: left;
  font-family: "Roboto Condensed";
  letter-spacing: 0.5px;
  font-style: italic;//problem is with this line
  font-weight:400;
`;

It is giving me the error:

Uncaught (in promise) Error: Could not resolve font for undefined, fontWeight 400

Upvotes: 4

Views: 7814

Answers (2)

Tom
Tom

Reputation: 114

When you register your fonts, you need to make sure to include a variant for each fontStyle you wish to use. For example:

Font.register({
  family: 'Roboto',
  fonts: [
    { src: '<path-to-normal-font-variant>' },
    { src: '<path-to-italic-font-variant>', fontStyle: 'italic' },
    ...
  ]
});

Upvotes: 7

IVAN PAUL
IVAN PAUL

Reputation: 179

const Italic = styled.Text`
  font-size: "12px";
  lineheight: "20px";
  text-align: left;
  font-family: "Roboto Condensed";
  letter-spacing: "0.5px";
  font-style: "italic";//problem is with this line
  font-weight:400;
`;

where ever you are suffixing px needs to be in either single or double quotes and font-style: value(italic) need to be in double quotes as well.

Upvotes: 2

Related Questions