【发布时间】:2016-05-03 19:51:08
【问题描述】:
我目前正在使用以下代码使用 TIKA 库提取 PDF 文件的内容和元数据。有没有办法读取特定页面或将解析限制在 TIKA 的前几页?
public static void main(final String[] args) throws IOException,TikaException, SAXException {
BodyContentHandler handler = new BodyContentHandler();
Metadata metadata = new Metadata();
FileInputStream inputstream = new FileInputStream(new File("test/test.pdf"));
ParseContext pcontext = new ParseContext();
//parsing the document using PDF parser
AutoDetectParser pdfparser = new AutoDetectParser();
pdfparser.parse(inputstream, handler, metadata,pcontext);
//getting the content of the document
System.out.println("Contents of the PDF :" + handler.toString());
//getting metadata of the document
//System.out.println("Metadata of the PDF:");
String[] metadataNames = metadata.names();
System.out.println(metadata.get("xmpTPg:NPages"));
for(String name : metadataNames) {
System.out.println(name+ " : " + metadata.get(name));
}
}
【问题讨论】:
标签: java pdf apache-tika