通过 Java 从 PDF 提取字体

Contents
[ ]

当您需要审计文档排版、检查嵌入资源或在转换或归档工作流之前验证字体使用情况时,请使用字体提取。

  1. 使用 Document 实例打开源 PDF。
  2. 调用 document.getFontUtilities().getAllFonts() 收集每个 Font 由文档引用的资源。
  3. 遍历已提取的 Font 对象,并从字体元数据中读取每个字体名称。
  4. 打印字体名称,以便对文档排版进行审计或导出。
public static void extractFonts(Path inputFile) {
    try (Document document = new Document(inputFile.toString())) {
        Font[] fonts = document.getFontUtilities().getAllFonts();
        for (Font font : fonts) {
            System.out.println(font.getFontName());
        }
    }
}