Font which support Multilanguage characters

We have an application where end user can provide multilanguage characters in a data and we need to print that in a pdf or doc file.
Arial Unicode MS is a paid font so we cannot use that.
Another alternative we had used is to apply Noto Sans font.

Below is the code :

Document w_Doc = w_Bldr.getDocument();
String fontsFolder = "/data/multifonts/";
FontSettings.setFontsFolder(fontsFolder, true);

multifonts folder has NotoSansMonoCJKhk-Regular.otf,NotoSansMonoCJKjp-Regular.otf and NotoSansThai-Regular.ttf and this is installed in our system.

Now when we print pdf file using aspose jar in java then the Thai characters (การพัฒนา) are getting corrupted on print whereas chinese japanese characters are working fine.
If only NotoSansThai-Regular.ttf is kept in the folder than Thai characters are properly printed.

We are using very old version of aspose 2.3.1 jar.
Upgrading the jar is currently not possible as it will need entire revamp.

So to support wide range of characters how do we handle this?
So that a single font can be applied for whole document and will support these data.

@ruchita93

To handle multi-language characters in your application and ensure they are printed correctly in PDF or DOC files using Aspose, you can follow these steps:

  1. Font Selection: Since Arial Unicode MS is a paid font, you can use the Noto Sans family, which is free and supports a wide range of characters, including Thai, Chinese, and Japanese. Ensure you have the necessary Noto Sans font files available in your system.

  2. Font Settings Configuration: Set the fonts folder in your application to include the directory where your Noto Sans fonts are stored. This can be done using the FontSettings class in Aspose. Here’s an example of how to set it up in Java:

    Document w_Doc = w_Bldr.getDocument();
    String fontsFolder = "/data/multifonts/";
    FontSettings.setFontsFolder(fontsFolder, true);
    
  3. Using Multiple Fonts: If you have multiple font files (like NotoSansMonoCJKhk-Regular.otf, NotoSansMonoCJKjp-Regular.otf, and NotoSansThai-Regular.ttf), ensure that they are all included in the specified fonts folder. However, if you notice that Thai characters are getting corrupted when using multiple fonts, it may be due to font substitution issues.

  4. Fallback Font Configuration: To ensure that all characters are rendered correctly, you can set a default font that will be used when a specific character is not available in the selected font. This can be done by configuring the default font substitution settings:

    FontSettings.DefaultInstance.SubstitutionSettings.DefaultFontSubstitution.DefaultFontName = "Noto Sans";
    
  5. Testing with Different Fonts: If you find that Thai characters are only printed correctly when using NotoSansThai-Regular.ttf alone, consider using a fallback mechanism where you specify that if a character is not found in the primary font, it should fall back to the Thai font.

  6. Document Rendering: When rendering the document, ensure that the font settings are applied correctly. You can check for any warnings related to font substitution during the document save process, which can help identify if any fonts are missing.

Here’s a sample code snippet that demonstrates how to set up the font settings and handle potential font substitution:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Set the font to a specific one
builder.Font.Name = "Noto Sans";
builder.Writeln("This is a test with multi-language characters: การพัฒนา");

// Save the document
doc.Save("output.pdf");

By following these steps, you should be able to support a wide range of characters in your documents without encountering issues related to font compatibility. If you continue to experience problems, consider isolating the fonts being used and testing them individually to identify any specific issues.

If upgrading your Aspose library is an option in the future, it may also provide additional features and improvements for handling fonts and multi-language support.

Feel free to reach out if you have any further questions or need additional assistance!

FontSettings.DefaultInstance.SubstitutionSettings.DefaultFontSubstitution.DefaultFontName = “Noto Sans”;
This cannot be used as we are using older aspose version.

@ruchita93 Please try loading Noto font fallback settings. Please see FallbackSettings.loadNotoFallbackSettings(). Please see our documentation for more information:
https://docs.aspose.com/words/java/manipulate-and-substitute-truetype-fonts/#font-fallback-settings-from-xml

The aspose version we are using is 2.3.1 which is very old version.
So these classes and methods are not available i.e. I cannot initialize
FontSettings fontSettings = new FontSettings(); – This gives compilation error as its not available.
Since I am not able to create the object I am not able to load the fallback settings.

fontSettings.getFallbackSettings().loadNotoFallbackSettings();

Also

String fontsFolder = "/data/multifonts/";
FontSettings.setFontsFolder(fontsFolder, true);

Why this is not working and only fallbacksettings is the option?

@ruchita93 You are right, 2.3.1 version is a really old version. We have made a lot of fixes and improvements since then. So I would suggest you to update to the latest 24.10 version of Aspose.Words.

What another alternate approach can be done so that this case is handled?
Currently upgrade is not possible.

@ruchita93 I am afraid. I cannot suggest a solution for a such old version of Aspose.Words.