通过 Python 提取 PDF 中的字体

Contents
[ ]

使用 文档 打开 PDF 并调用 font_utilities.get_all_fonts() 检索所有可用的 Font 文档引用的对象。这在审计嵌入字体、在转换前检查字体可用性或分析文档资源时非常有用。

  1. 打开源 PDF 作为 Document.
  2. 调用 document.font_utilities.get_all_fonts() 获取字体集合。
  3. 遍历返回的 Font 对象。
  4. 读取并打印每个 font.font_name 值。

    import aspose.pdf as apdf
    from os import path

    path_infile = path.join(self.dataDir, infile)

    # Open PDF document
    document = apdf.Document(path_infile)

    fonts = document.font_utilities.get_all_fonts()
    for font in fonts:
        print(font.font_name)