We have the following problem:
We are using Aspose Words to generate a PDF document from an HTML file. To do this, we create an empty document and import the HTML into it. As expected, the PDF is not generated correctly on Linux because the necessary fonts for displaying Korean characters are missing. On Windows, however, the document is generated with the correct fonts.
To work around the missing font issue on Linux, we created a template with all fonts embedded. However, even with this approach, the PDF document is generated on Linux without the Korean characters. On Windows, the document is generated correctly.
If we save the HTML content directly in the template and generate the PDF document on Linux, the characters appear correctly.
@fatemeh23
The issue you’re experiencing with PDF generation on Linux compared to Windows is likely due to the absence of necessary TrueType fonts for rendering Korean characters on the Linux system. While Windows typically has these fonts installed, Linux distributions often do not include them by default.
To resolve this, you can take the following steps:
-
Install TrueType Fonts on Linux: You can either copy the required .TTF
or .TTC
font files from a Windows machine to your Linux system or install a package that includes Microsoft TrueType fonts. For example, on Ubuntu, you can install the ttf-mscorefonts-installer
package, which provides many common Windows fonts.
-
Use FontSettings in Aspose.Words: After ensuring that the necessary fonts are available on your Linux system, you can specify the font location in your Aspose.Words application using the FontSettings
class. This allows Aspose.Words to locate and use the installed fonts when generating PDFs.
-
Fallback Fonts: If you are still facing issues, consider using font fallback settings. Aspose.Words allows you to define fallback fonts that can be used when the primary font does not support certain characters. You can load predefined fallback settings or create your own XML configuration for font fallback.
Here is a simple code example to set up font settings in Aspose.Words:
// Create a new document
Document doc = new Document("input.html");
// Set up font settings
FontSettings fontSettings = new FontSettings();
fontSettings.SetFontsSources(new[] { new FolderFontSource("/path/to/fonts", true) });
doc.FontSettings = fontSettings;
// Save the document as PDF
doc.Save("output.pdf");
By following these steps, you should be able to generate the PDF document correctly on Linux, ensuring that Korean characters are displayed as intended. If you continue to experience issues, please check for any font substitution warnings that may indicate which fonts are being used during the rendering process.
Thats not a solution. We need to transport the fonts with a document template. So we create a template with all installed fonts under windows and use it in the merge process in linux. As i wrote… without the html import, with the embedded content the pdf looks fine. it seems that aspose under windows can automatically substitute the font - but under linux it does not work. I can upload an example
@fatemeh23 Could you please attach your template with embedded fonts, sample HTML, the problematic and expected output PDF documents? We will check the issue and provide you more information.
Attached you will find a zip with examples. Hope i have choose the right file names in order for your understanding
fonttest_linux.zip (9,5 MB)
fonttest_windows.zip (9,5 MB)
@fatemeh23 Thank you for additional information. The problem occurs because the fonts embedded in your document does not have the required glyphs. So some glyphs are not rendered properly. When you render document in Windows environment there following fonts are used in PDF:
When render without Windows fonts, PDF document used the following fonts:
As you can see Batang
and SimSun
are used in the correctly rendered PDF. But these fonts are not embedded into your template.