Posted 10 March 2020, 9:05 am EST
Hello,
I’m generating a document and want to save it as a pdf. Locally this works fine but when running from a server I get the following error:
TextFormat has no associated Font, and a default font could not be found. To avoid this situation, assign an available font to FontCollection.SystemFonts.DefaultFont if it is null.
I asume the server doesn’t have access to certain fonts so I followed what the error recomends by doing the following:
_fontCollection = new FontCollection {DefaultFont = StandardFonts.Times};
_fontCollection.RegisterDirectory("./Fonts");
var font = _fontCollection.FindFamilyName("CorpoS");
if (font != null)
{
_fontCollection.DefaultFont = font;
}
_logger.LogInformation($"Default font: {(_fontCollection.DefaultFont != null ? _fontCollection.DefaultFont.FontFamilyName : "not found.")} - Font count: {_fontCollection?.Count}");
doc.SaveAsPdf(memoryStreamPdf, _fontCollection);
I still get the same error but my logging logs the following:
Default font: CorpoS - Font count: 4
So what am I doing wrong here?