如何使用pdfbox提取文本内容的字体样式? [英] How to extract font styles of text contents using pdfbox?
本文介绍了如何使用pdfbox提取文本内容的字体样式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用pdfbox库从pdf文件中提取文本内容。我可以提取所有文本,但找不到提取字体样式的方法。
I am using pdfbox library to extract text contents from pdf file.I would able to extract all the text,but couldn't find the method to extract font styles.
推荐答案
这不是提取字体的正确方法。要读取字体,必须遍历pdf页面并提取字体,如下所示:
This is not the right way to extract font. To read font one has to iterate through pdf pages and extract font as below:
PDDocument doc = PDDocument.load("C:/mydoc3.pdf");
List<PDPage> pages = doc.getDocumentCatalog().getAllPages();
for(PDPage page:pages){
Map<String,PDFont> pageFonts=page.getResources().getFonts();
}
这篇关于如何使用pdfbox提取文本内容的字体样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文