Fonts not loading in linux based Container

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?

@PramodMn

Why the fonts are not being picked up

  1. Aspose.Words only uses TrueType (TTF) fonts when it renders to a fixed‑page format (PDF, XPS, JPEG, HtmlFixed, etc.).
    • An OpenType / OTF font (e.g., Graphik‑Regular.otf) is ignored for those operations.
  2. The custom folder source is added correctly – the log shows the files exist – but because the OTF font is not a supported TrueType font, the whole source is effectively empty for rendering.
  3. The TTF font (Dottee‑Bold.ttf) should be recognized, but it will be skipped if the folder source is not reachable or if the process does not have read permission on /app/Resources.

What to do

Step Action
1 Use only TrueType fonts for any rendering to PDF/XPS/HtmlFixed/JPEG. Convert the OTF font to TTF or replace it with a TTF version.
2 Verify the container can read the folder: ls -l /app/Resources should show r permission for the user running the app.
3 Keep the code you already have – it is the correct way to register a custom folder source:
fontSettings.SetFontsSources(new FontSourceBase[] { new SystemFontSource(), new FolderFontSource("/app/Resources", true) });
4 Assign the FontSettings to LoadOptions before creating the Document (as you already do).
5 After the changes, re‑run the logging that enumerates the fonts. You should now see the TTF font listed, e.g.:
FontFamily : Dottee, Dottee Bold
6 Generate the document again – the text that uses the custom font will be rendered correctly in the output file.

Quick checklist

  • :white_check_mark: Font files are TTF (TrueType).
  • :white_check_mark: Files are present in /app/Resources and readable.
  • :white_check_mark: FolderFontSource path is absolute and points to the folder.
  • :white_check_mark: SetFontsSources is called before creating LoadOptions/Document.

If after converting the OTF to TTF you still do not see the font in the log, double‑check the file permissions inside the container and ensure the user running the .NET process has read access to /app/Resources. Once a TrueType font is successfully listed, Aspose.Words will embed and use it in the generated document.

@PramodMn

In this test code you are checking font source available in the newly created FontSettings instance. In the newly created FontSettings instance only SystemFontSource is available by default. So it is expected there is no FolderFontSource you have specified in another FontSettings instance.

By the way, you can set font sources globally using FontSettings.DefaultInstance. For example you can put this code on the application start or in the static constructor of your class and the specified font sources will be available globally in the current application domain:

FontSettings.DefaultInstance.SetFontsSources(new FontSourceBase[] { new SystemFontSource(), new FolderFontSource(@"C:\Temp\fonts", true) });

Could you please attach these fonts here for testing along with problematic input and output documents? We will check the issue and provide you more information.

Please find a sample Word doc
Sample.docx (20.5 KB)

and Fonts
Graphik-Regular.zip (73.2 KB)

@PramodMn Thank you for additional information. I have tested the scenario on my side and cannot reproduce the problem. Here is my test code:

string folder = @"/temp/";

License lic = new License();
lic.SetLicense(folder + "Aspose.Words.NET.lic");

FontSettings.DefaultInstance.SetFontsSources(new FontSourceBase[] { new FolderFontSource(@"/temp/fonts/Graphik-Regular", true), new SystemFontSource() });
PrintAvaialbleFonts(FontSettings.DefaultInstance);

Document doc = new Document(folder + "in.docx");
doc.WarningCallback = new FontSubstitutionWarningCallback();
doc.Save($@"{folder}out_linux.pdf");
public static void PrintAvaialbleFonts(FontSettings fs)
{
    foreach (FontSourceBase fsb in fs.GetFontsSources())
    {
        Console.WriteLine(fsb.Type);
        foreach (PhysicalFontInfo pfi in fsb.GetAvailableFonts())
        {
            Console.WriteLine(pfi.FullFontName);
        }
        Console.WriteLine("================================================");
    }
}

private class FontSubstitutionWarningCallback : IWarningCallback
{
    public void Warning(WarningInfo info)
    {
        if (info.WarningType == WarningType.FontSubstitution)
            Console.WriteLine(info.Description);
    }
}

My test Dockerfile

FROM mcr.microsoft.com/dotnet/runtime:9.0 AS base
WORKDIR /app
RUN apt-get update && apt-get install -y libfontconfig1

FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
WORKDIR /src
COPY ["TestNet.csproj", "."]
RUN dotnet restore "./TestNet.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "TestNet.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "TestNet.csproj" -c Release -r linux-x64 --no-self-contained -o /app/publish

FROM base AS final

WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "TestNet.dll"]

The output is the following:

FontsFolder
Dottee Bold
Graphik Regular
================================================
SystemFonts
DejaVu Sans Bold
DejaVu Sans
DejaVu Sans Mono Bold
DejaVu Sans Mono
DejaVu Serif Bold
DejaVu Serif
================================================

Theer are no font substitutions and the output PDF uses correct fonts: out_linux.pdf (32.5 KB)

Thanks Alexey, using the DefaultInstance of fontsettings seems to have made the trick for me.

@PramodMn It is perfect that you managed to resolve the problem. Please feel free to ask in case of any issues, we are always glad to help you.