Aspose.Words Fonts not rendering in Ubuntu while generating PDF using .NET Core

Hi Team,

I am using Aspose.Words to generate a PDF from a word template (after merging). I am able to generate a PDF when the application(.NET Core API) is running in my windows environment. But when the same application is hosted in a Linux Ubuntu environment then the fonts are not being rendered correctly.

I tried to place the windows fonts in a separate folder and used FontSettings class to map the fonts to the Document object but still the fonts are not rendering correctly.

Please let me know if there is a way to make the fonts render on Linux environment.

Thanks,
Tharun Chennuri

@tharunchennuri The fonts used in the document should be available in the environment where document rendering (conversion to PDF) is performed. If Aspose.Words cannot find the fonts the missed fonts are substituted. You can implement IWarningCallback to get notification about substituted fonts.
In your case you should either install the fonts in your Linux environment or put the fonts into a separate folder and use this folder as fonts source.

Hi @alexey.noskov,

Thanks for your reply. I installed TTFMsCoreFonts package and looks like only a set of fonts are supported. Is there a way/package using which we can get all the fonts get to working when converting to PDF in a linux distribution?

@tharunchennuri You can copy the required fonts from your Windows machine, put the fonts into a separate folder and use this folder as fonts source. But in this case there might be font licensing issues.
Alternatively, you can use free Google Noto fonts, but in this case, if Aspose.Words perform font substitutions, layout of the document might be not accurate.
https://docs.aspose.com/words/net/manipulating-and-substitution-truetype-fonts/#predefined-font-fallback-settings-for-google-noto-fonts

@alexey.noskov,

If we opt for the first option of copying over the fonts into a separate folder in Linux Distribution and then refer it. Would it need any licenses as such as we are moving windows specific fonts into a Linux environment.

@tharunchennuri Unfortunately, I am not an expert in font licensing. So I cannot consult you regarding fonts deployment questions. Different fonts might have different licenses and distribution rules.

@alexey.noskov,

I am skeptical about copying fonts as we are copying fonts not installing. In Aspose code i found something that we can embed all fonts. Like below.

private static byte[] SaveRenderedPdf(Document doc)
{
    MemoryStream istream = new MemoryStream();
    PdfSaveOptions saveOptions = new PdfSaveOptions();
    saveOptions.EmbedFullFonts = true;
    saveOptions.SaveFormat = SaveFormat.Pdf;
    doc.Save(istream, saveOptions);
    return istream.ToArray();
}

Here i thought EmbedFullFonts will embed all the fonts without me copying fonts explicitly.

Also is there any way we can get the fonts to work.

@tharunchennuri Fonts are always embedded into PDF document upon saving. But Aspose.Words needs a place where to get these fonts to build document layout and embed them into the output PDF or XPS document. So the font files must be physically present on the machine where conversion is performed and must be available to Aspose.Words.