Render Text Formatted with Amharic Font Nyala during Converting Word DOCX to PDF | Java

Hello,

Hope you are doing well!

I am trying to convert a .docx file (containing Amharic/Nyala font) to pdf. This specific font is not getting displayed correctly after the conversion. I am uploading the input and output file. It would be great if you could help me in this matter.

Aspose Version: aspose-words-19.3-jdk17

Thank you in advance.

Regards,
Amey

Input_file.docx (35.8 KB)
Output_file.pdf (31.1 KB)

@avaidya,

Please install these fonts on your machine where you want to perform this Word to PDF conversion. Please refer to the following sections of documentation:

Also, please upgrade to the latest 21.9 version of Aspose.Words for Java.

Hello Awais,

Thank you for your quick response. I would like to mention that I am working on Windows OS so I am not really sure if TrueType Fonts would help. As per your suggestion, I upgraded to the latest 21.9 version of Aspose.Words for Java. Unfortunately it did not work. I am still getting the same output as before. I would like to share a piece of code that I am using while converting a document.

Document doc = new Document(srcFilePath);
PdfSaveOptions options = new PdfSaveOptions();
options.setCompliance(PdfCompliance.PDF_17);

doc.save(destFilePath, options);

Could you please guide me in the right direction? Are there any specific APIs that I can call on options to fix this issue? Also, do you know how to set the encoding format and will it help in this case?

Any input is appreciated.

Thank you,
Amey

@avaidya,

Please first check which fonts are being used in the source Word document? Aspose.Words will throw missing fonts related warning messages if the fonts are not installed in Windows OS.

In this case, your Word document uses Nyala and Times New Roman fonts. Please copy the latest versions of these required font files into a separate folder inside your Windows machine and try running the following code of latest 21.9 version of Aspose.Words for Java:

Document doc = new Document("C:\\Temp\\word.docx");

FontSettings fontSettings = new FontSettings();
addFontFolder(fontSettings, myDir + "Custom Fonts Folder/");
doc.setFontSettings(fontSettings);

doc.save("C:\\Temp\\word to.pdf");

private static void addFontFolder(FontSettings fontSettings, String folder)
{
    FontSourceBase[] fontSourceBases = fontSettings.getFontsSources();
    FontSourceBase[] newFontSourceBases = new FontSourceBase[fontSourceBases.length + 1];
    System.arraycopy(fontSourceBases, 0, newFontSourceBases, 0, fontSourceBases.length);
    newFontSourceBases[newFontSourceBases.length - 1] = new FolderFontSource(folder, true);
    fontSettings.setFontsSources(newFontSourceBases);
}