我已经在以前的版本中看到了如何做到这一点,如下所示:
How to extract font styles of text contents using pdfbox?
但是我认为getFonts()方法现在已经被移除了。我想在新版本的PDFBox中检索一个从文本到字体(Map<String, PDFont>)的映射,但我不知道如何检索。
谢谢
卡比尔
发布于 2016-07-14 16:57:20
执行以下操作:
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
}
}发布于 2020-05-11 13:35:37
PDFMetaData pdfMeta = new PDFMetaData();
PDDocument document = PDDocument.load(new File("/Users/ban.pdf"));
PDPage page = document.getPage(0);
PDResources res = page.getResources();
for (COSName fontName : res.getFontNames())
{
PDFont font = res.getFont(fontName);
pdfMeta.setFontName(font);
}发布于 2016-07-14 17:07:42
对于PDFBox 2.x,您要链接的答案的修订代码是
PDDocument doc = PDDocument.load("C:/mydoc3.pdf");
for(PDPage page : doc.getPages()){
// get the names of the fonts in the resources dictionary
Iterable<COSName> iterable = page.getResources().getFontNames();
// to get the font for each item call
// page.getResources().getFont(COSName name);
}https://stackoverflow.com/questions/38369096
复制相似问题