I’m using Aspose.Words for .NET inside a Linux Docker container to generate Word document and then convert them to PDF or HTML files based on use case. Issue is that the output fonts often don’t match the original template.
For HTML,
var htmlSaveOptions = new HtmlFixedSaveOptions()
{
ExportEmbeddedCss = true,
ExportEmbeddedFonts = true,
ExportEmbeddedImages = true,
ExportEmbeddedSvg = true,
Encoding = UTF8WithoutBom,
};
For PDF,
PdfSaveOptions savePdfOptions = new PdfSaveOptions();
savePdfOptions.SaveFormat = SaveFormat.Pdf;
docContent.Save(outputStream, savePdfOptions);
I’ve gone through some related documentation about fonts. However, what’s the most scalable and performant way to ensure accurate font rendering in a containerized environment — especially when scaling across multiple containers? Does adding font files (TTF) in code base is good idea? Does Aspose.Words support font caching?
Please suggest the best possible solution for resolving font-related issues.
@abhishekouta The problem on your side might occur because the fonts used in your input document are not available on the machine where document is converted to PDF. If Aspose.Words cannot find the font used in the document, the font is substituted. This might lead into fonts mismatch and document layout differences due to the different fonts metrics. You can implement IWarningCallback to get notifications when font substitution is performed.
Please see our documentation to learn where Aspose.Words looks for fonts:
https://docs.aspose.com/words/net/specifying-truetype-fonts-location/
Thank you @alexey.noskov for the prompt response.
I have referred to this documentation, but I’m wondering which approach would be better in terms of performance.
Here are the options I’m considering:
- Mount the required fonts into the Docker container and make them available at the system level.
- Include the required fonts in the codebase and use
FolderFontSource
to access them via a relative path.
I may need these fonts every time a document is processed. Even if I pre-load the font cache earlier using save-and-load-a-font-search-cache, do I still need to explicitly specify the font name while processing the document?
Given this, what would you recommend as the most performant solution that also preserves the original fonts?
@abhishekouta There should not be difference in performance between two approaches. Aspose.Words scans for fonts once on the first use of the library in the app domain and caches the information. But it is better to test the approaches on your side with real data to select the most suitable for you.