通过 Python 提取 PDF 中的字体
Contents
[
Hide
]
使用 文档 打开 PDF 并调用 font_utilities.get_all_fonts() 检索所有可用的 Font 文档引用的对象。这在审计嵌入字体、在转换前检查字体可用性或分析文档资源时非常有用。
- 打开源 PDF 作为
Document. - 调用
document.font_utilities.get_all_fonts()获取字体集合。 - 遍历返回的
Font对象。 - 读取并打印每个
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)