3

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

keikai
  • 14,085
  • 9
  • 49
  • 68
Knowledge Seeker
  • 526
  • 7
  • 25
  • try putting font-size, lineheight and letter-spacing in double quotes (font-size: "12px") or single quotes etc. Though the suffix px is not needed. React will automatically append a “px” suffix to certain numeric inline style properties. If you want to use units other than “px”, specify the value as a string with the desired unit. – IVAN PAUL Mar 16 '20 at 11:53
  • nothing happens @IVANPAUL – Knowledge Seeker Mar 16 '20 at 11:59
  • Apologies forgot, to add that font-style : "italic" should also be in double or single quotes. https://stackoverflow.com/a/50556938/6033636 refer to this answer for more – IVAN PAUL Mar 16 '20 at 12:04

2 Answers2

6

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' },
    ...
  ]
});
Tom
  • 104
  • 1
  • 4
2
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.

IVAN PAUL
  • 157
  • 1
  • 3
  • 15