如何从PDFBox 2.0.2中的PDDocument提取字体 [英] How to extract fonts from PDDocument in PDFBox 2.0.2
本文介绍了如何从PDFBox 2.0.2中的PDDocument提取字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经在以前的版本中看到了如何做到这一点:
I have seen how to do this in previous versions like below:
但是我认为getFonts()方法现在已被删除.我想在新版本的PDFBox中检索文本到字体(Map<String, PDFont>
)的映射,但是我不知道如何.
But I think the getFonts() method has been removed now. I want to retrieve a map of texts to fonts (Map<String, PDFont>
) in the new version of PDFBox but I have no idea how.
谢谢
Kabeer
推荐答案
执行以下操作:
PDDocument doc = PDDocument.load("C:/mydoc3.pdf");
for (int i = 0; i < doc.getNumberOfPages(); ++i)
{
PDPage page = doc.getPage(i);
PDResources res = page.getResources();
for (COSName fontName : res.getFontNames())
{
PDFont font = res.getFont(fontName);
// do stuff with the font
}
}
这篇关于如何从PDFBox 2.0.2中的PDDocument提取字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文