How to use @font-face in iText7 pdfHTML?

Viewed 160

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

0 Answers
Related