Following Specify TrueType Fonts Location in C#|Aspose.Words for .NET , I’m trying to load custom fonts in Linux based container.
I modified my code to include both System and Custom Fonts from Resources folder.
var fontSettings = new Aspose.Words.Fonts.FontSettings();
fontSettings.SetFontsSources(new Aspose.Words.Fonts.FontSourceBase[] { new Aspose.Words.Fonts.SystemFontSource(), new Aspose.Words.Fonts.FolderFontSource("/app/Resources", true) });
var loadOptions = new LoadOptions
{
FontSettings = fontSettings
};
var document = new Aspose.Words.Document(documentData, loadOptions);
I created a Resources folder in my solution to include a Graphik Medium OTF font and Dottee Bold TTF Font. Set both file property as Copy always.
My Docker Container has copy command to Copy all files from Publish to /app folder.
I added logs to display all the fonts available.
var fontSettings = new Aspose.Words.Fonts.FontSettings();
var sources = fontSettings.GetFontsSources();
foreach (var source in sources)
{
var folder = source is FolderFontSource f ? f.FolderPath : "System";
this._logger.LogInformation($"Font Source: {source.GetType().Name}, {folder}");
foreach (var info in source.GetAvailableFonts())
{
this._logger.LogInformation($"FontFamily : {info.FontFamilyName}, {info.FullFontName}");
}
}
When i tried to Generate a Document, my final document didn’t had the fonts and from Logs couldn’t find the Second Source or fonts.
|4:22:31.746 PM|Trace|Severity level: Information, Message: Font Source: SystemFontSource, System |
|4:22:31.760 PM|Trace|Severity level: Information, Message: FontFamily : DejaVu Sans, DejaVu Sans Bold|
|4:22:31.761 PM|Trace|Severity level: Information, Message: FontFamily : DejaVu Sans, DejaVu Sans|
|4:22:31.761 PM|Trace|Severity level: Information, Message: FontFamily : DejaVu Sans Mono, DejaVu Sans Mono Bold|
|4:22:31.761 PM|Trace|Severity level: Information, Message: FontFamily : DejaVu Sans Mono, DejaVu Sans Mono|
|4:22:31.761 PM|Trace|Severity level: Information, Message: FontFamily : DejaVu Serif, DejaVu Serif Bold|
|4:22:31.761 PM|Trace|Severity level: Information, Message: FontFamily : DejaVu Serif, DejaVu Serif|
Further debugging, I added logs to confirm if the Fonts are copied and available at the container. From Logs I could see them available.
|4:22:30.440 PM|Trace|Severity level: Information, Message: File: /app/Resources/Graphik-Regular.otf|
|4:22:30.441 PM|Trace|Severity level: Information, Message: File: /app/Resources/Dottee-Bold.ttf|
What could be the possible reason for fonts not being loaded?