我目前正在使用以下代码使用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));
}
}
答案 0 :(得分:1)
TIKA并不真正处理网页,但它会在页面之前发送<div><p>
之后发送</p></div>
。您可以修改处理程序startElement
和endElement
以搜索这些字符。
如果您需要更多信息,可以查看topchef
的答案
https://stackoverflow.com/a/6271696/2197529