Word DOC with Chinese Font Characters to PDF Conversation using Java over Linux

Hi

I’m converting doc file to pdf file using below code
this is working fine in Windows Environments but Not working in Linux environment

Linux OS : CentOS Linux release 7.6.1810 (Core)
Im using the Below code to Convert doc to pdf

Document document = new Document(inputStream);
document.save(outStream, SaveFormat.PDF);

Multilingual template.docx (11.2 KB)

Tried these two approaches still its not working fine

https://stackoverflow.com/questions/42556347/pdf-in-aspose-made-is-not-showing-chinese-characters

https://docs.aspose.com/words/java/install-truetype-fonts-on-linux/

image-2021-07-15-19-16-11-840.jpg (139.8 KB)

@rabinintig,

Please copy the latest versions of following font files from Windows machine into a separate folder inside Linux machine:

  • Calibri
  • MS Gothic
  • Microsoft JhengHei
  • Malgun Gothic
  • Leelawadee UI

And then try running the following code of latest 21.7 version of Aspose.Words for Java:

Document doc = new Document("Multilingual template.docx");

FontSettings fontSettings = new FontSettings();
addFontFolder(fontSettings, "path to your custom fonts folder/");
doc.setFontSettings(fontSettings);

doc.save("output.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);
}

Thank you so much, its working fine.

1 Like

hi @awais.hafeez Its was working for the above document but im still facing issue for the document Sample_Doc.docx (13.0 KB)

During Preview Thai and Korean languages are not supported

Screenshot.PNG (8.2 KB)

Note: Now issue occurs in Windows and Linux instances

@rabinintig,

For the proper rendering of this particular Word document, the following fonts need to be installed/available on the machine:

  • Calibri
  • Georgia
  • Tahoma
  • Lucida Sans Unicode
  • Angsana New
  • Times New Roman

Please also try installing the 'Arial Unicode MS’ font file on your machine where you are performing DOCX to PDF conversion by using Aspose.Words. You may download it from following link: