MacOS如何添加缺失的字体

//更新目录(刷新内容和页码)
document.updateFields();
更新目录后,页码和目录页码不符,按照官方说法,是因为字体缺失,如何检测和安装缺失的字体?
开发环境:MacOS

@JOOL

请问您能否提供更多关于您使用的Aspose.Cells代码的细节?

代码比较多,包含表格、文本填充等;


@JOOL 请尝试使用以下代码检查警告:

Document doc = new Document("input.docx");
doc.setWarningCallback(new FontSubstitutionWarningCollector());
doc.save("output.pdf");

private static class FontSubstitutionWarningCollector implements IWarningCallback {
    public void warning(WarningInfo info) {
        if (info.getWarningType() == WarningType.FONT_SUBSTITUTION) {
            System.out.println(info.getDescription());
        }
    }
}

如果会发现一些遗漏的字体,您需要在MacOS上手动查找并安装,或设置字体文件夹。以下文章可能对您有用:
https://docs.aspose.com/words/java/specify-truetype-fonts-location/

我已经设置了自定义字体目录,并且已经放入了字体

但是还是有以下错误,是需要什么特殊命名吗
Font ‘楷体’ has not been found. Using ‘SimHei’ font instead. Reason: font info substitution.
Font ‘仿宋’ has not been found. Using ‘SimHei’ font instead. Reason: font info substitution.
Font ‘Times New Roman’ has not been found. Using ‘SimHei’ font instead. Reason: font info substitution.
Font ‘阿里巴巴普惠体 R’ has not been found. Using ‘SimHei’ font instead. Reason: font info substitution.
Font ‘仿宋_GB2312’ has not been found. Using ‘SimSun’ font instead. Reason: font info substitution.

@JOOL 您的文件夹似乎不包含所需的字体,因此您需要添加所有必要的字体,或者您可以使用以下代码定义您的文件夹和系统文件夹(如果此文件夹包含其他字体):

FontSettings.getDefaultInstance().setFontsSources(
		new FontSourceBase[] { new SystemFontSource(), new FolderFontSource("\\your_fonts\\", true, 1) });

Wps Office中的【楷体】【仿宋】 是缺失的,应该如何下载到这样的字体呢

已经安装了楷体,但是扫描结果还是有楷体

@JOOL 我在网上只找到了这种字体:

Fonts.zip (4.9 MB)

遗憾的是,我找不到任何其他字体,也许它可以在带有中文区域设置的 Windows 系统上使用。

可能因为字体名称不同,所以还是漏掉了这种字体? 您可以在这里查看:

这样,您就可以尝试用您拥有的字体名称来替代该字体:

FontSubstitutionRule fontSubstitutionRule = fontSettings.getSubstitutionSettings().getFontInfoSubstitution();
fontSubstitutionRule.setEnabled(true);

// Add a font substitution rule.
fontSettings.getSubstitutionSettings().getTableSubstitution().addSubstitutes("楷体", new String[]{"您的字体"});

使用替换字体,会影响目录刷新吗

@JOOL 如果说到目录,不同的字体可能会显示不同的页面,因此会对目录产生影响。 不过,"Aspose.Words "是模仿 "MS Word "的行为,在显示输出结果时有时会与 WPS 不同。