4

I have added a directory containing Roboto font to the FontProvider. The Pdf can find Roboto font, but it doesn't work as expected. It always uses Roboto-Black when I use font-weight: 900; font-style: Bold; and Roboto-Light instead of Roboto-Regular, when I use font-weight: normal;font-style: normal. That's why I want to use @font-face in CSS. But I'm unable to make it done. Here is what I have done:

FontProvider fontProvider = new DefaultFontProvider(false,false,false);
fontProvider.AddDirectory(fonts);
properties.SetFontProvider(fontProvider);
...

In CSS:

@font-face {
    font-family: 'Roboto';
    src: local('Roboto-Regular.ttf');
    src: local('Roboto-Regular.ttf') format('truetype'), url('Fonts/Roboto/Roboto-Regular.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
}


.test {
    font-family: 'Roboto';
    background-color: #c9c9c9;
    font-weight: normal;
    font-style: normal;
}
<div class="test">
    Hello World. This is Roboto Font.
</div>

Here is the result

Amedee Van Gasse
  • 7,280
  • 5
  • 55
  • 101
  • If you use `@font-face` declaration then you don't need to customize the font provider. Could you attach an archive with your HTML and all accompanying resources (fonts)? It's expected that such HTML is rendered correctly in Chrome (i.e. your desired font is used). Once you have that sample and it is not converted correctly by iText it becomes a point for investigation. As a lot of things depend on folder structure here, it's hard to help without that info – Alexey Subach Sep 09 '20 at 21:19

0 Answers0