facebooktwittermenuarrow-up

GemBox Support Forum

Saving to PDF with private fonts on Linux

Hello,

I try to use private fonts on Linux. On Windows this code works, but not on Linux.

FontSettings.FontsBaseDirectory = "./Fonts";

var doc = DocumentModel.Load(templateStream);
Console.Write($"Saving {filename}...");

try
{
    doc.Save($"Output_{Guid.NewGuid()}.pdf", new PdfSaveOptions());
    Console.WriteLine("Success");
}
catch (Exception ex)
{
    Console.WriteLine($"Error: {ex}");
}

image

I get this exception:

System doesn’t contain any font files, use private or embedded fonts.\nSee: https://www.gemboxsoftware.com/document/examples/private-fonts/103

What am I doing wrong?

Regards,
Robert

Additionally, I’m running in Kubernetes. My base image (ASP.NET Core 3.1) probably does not have any fonts installed, but one of the fonts used is available.

Hi Robert,

After much investigation, it was concluded that even though the input Word document used only “Univers” font in its text content (which was provided with private font files), the problem occurred because the document’s default font was “Calibri”.

This default was coming from the used “Office” theme:

office-theme-in-word

One way to resolve this is to change the default font, like the following:

var doc = DocumentModel.Load(templateStream);
doc.DefaultCharacterFormat.FontName = "Univers";
// ...

Or add “Calibri” font files as private fonts as well because as you suspected, those base image (aspnet:3.1-buster, aspnet:3.1-alpine, etc.) don’t have any fonts installed.

Or you can install ttf-mscorefonts-installer package on those images using “Dockerfile”.

Regards,
Mario