Fonts embed issue in linux ubuntu docker container (using the aspose.word(.net))

We created the MS word templates in windows machine and using the basic Font like Arial. We have deployed our application in Linux ubuntu docker container. But output of generated document is not containing the Arial font whereas coming some other font.

We tried below approaches to solve this but it would not work.

  1. Embed the Font itself inside the MS word templates, it works but size of document increased dramatically from 54kb to 4985kb and generation time increment many folds so this approach would be feasible for our case.
  2. Tried to install fonts in Linux container but due to compatibility issues, difficult to install windows font to Linux container.

Using the aspose.word(.net) ver 21.7 and our application is .Net core 3.1

Please suggest on this issue.

@nitesh.puri,

The problem occurs because In Docker, Aspose.Words can most likely not find the required fonts. You can mount a custom folder with fonts and specify it in font settings. See the following article for more information:

For example, please copy the latest versions of required font files from Windows 10 machine into a separate folder inside Linux Ubuntu machine and try running the following C# code of latest 21.8 version of Aspose.Words for .NET:

Document doc = new Document("word.docx");

FontSettings fontSettings = new FontSettings();
AddCustomFontsFolder(fontSettings, " path to custom fonts folder\ ");
doc.FontSettings = fontSettings;

doc.Save("output.pdf");

private static void AddCustomFontsFolder(FontSettings fontSettings, string folder)
{
    ArrayList fontSources = new ArrayList(fontSettings.GetFontsSources());

    // Add a new folder source which will instruct Aspose.Words to search the following folder for fonts.
    FolderFontSource folderFontSource = new FolderFontSource(folder, true);

    // Add the custom folder which contains our fonts to the list of existing font sources.
    fontSources.Add(folderFontSource);

    // Convert the Arraylist of source back into a primitive array of FontSource objects.
    FontSourceBase[] updatedFontSources = (FontSourceBase[])fontSources.ToArray(typeof(FontSourceBase));

    // Apply the new set of font sources to use.
    fontSettings.SetFontsSources(updatedFontSources);
}