richard-scryber / scryber.core

Scryber.Core is a dotnet 6 html to pdf engine written entirely in C# for creating beautiful flowing documents from html templates including css styles, object data binding and svg drawing.
Other
194 stars 31 forks source link

Referencing fonts in code #30

Closed awardle closed 3 years ago

awardle commented 3 years ago

Is there a way to set the font options directly from code without using an "appsetting.json" file?

I need to reference some fonts that I have included in my project.

awardle commented 3 years ago

Noticed from reading the unit tests, a font configuation could be made as follows:

IScryberConfigurationService service = ServiceProvider.GetService<IScryberConfigurationService>();
service.FontOptions.Register = new[]
{
    new FontRegistrationOption
    {
        Family = "Roboto",
        File = "Fonts/Roboto-Regular.ttf"
    }
};
richard-scryber commented 3 years ago

Hi Alex

That's awesome you sorted. And works brilliantly! It is can also possible to reference a font from the css style in any document using the font-face selector (as of v5.0.4 package)

@font-face { font-family: Roboto; src: url(../Fonts/Roboto-Regular.ttf); }

Adding it, so it may help, or help someone else.