Substitute Specific Fonts in Word Document with Arial during DOCX to PDF Conversion using Java

Font ‘宋体’ has not been found. Using ‘PingFang SC’ font instead. Reason: font info substitution.


it Looks useless


For the proper rendering of Word document to PDF, XPS, HTML Fixed or Image formats by using Aspose.Words for Java, you need to install the required fonts (which are used in source Word document) on the machine. Please refer to the following sections of documentation:

If you don’t want to install the fonts, then you can simply copy the latest versions of required font files into a separate folder and try running the following code of latest 21.4 version of Aspose.Words for Java:

Document doc = new Document("input.docx");

FontSettings fontSettings = new FontSettings();
addFontFolder(fontSettings, myDir + "CustomFonts/");

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);

this is i know but I found that some fonts are not available on the machine when converting word to pdf, but aspose uses fonts that I don’t know, but I clearly specify the default font


If instead of ‘PingFang SC’, you want Aspose.Words for Java to replace ‘宋体’ font with ‘Times New Roman’ or any other font, then please use the following code:

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

FontSettings fs = new FontSettings();
fs.getSubstitutionSettings().getTableSubstitution().addSubstitutes("宋体", new String[]{"Times New Roman"});

But fonts have many formats, such as Heiti SC Light and Heiti SC. I wonder if it can be replaced by regular expressions. All the beginning of Heiti SC is replaced with Arial.


Please try the following code

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

FontSettings fs = new FontSettings();
ArrayList listOfFonts = new ArrayList();
// Collect complete Font Names that start with Heiti
FontInfoCollection fonts = doc.getFontInfos();
for (int i = 0; i < fonts.getCount(); i++)
    if (fonts.get(i).getName().startsWith("Heiti"))
// Add Font Substitutions
for (int i = 0; i < listOfFonts.size(); i++)
            new String[]{"Arial"});