【问题标题】:How to read first few pages of a PDF file using TIKA如何使用 TIKA 阅读 PDF 文件的前几页
【发布时间】: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


    【解决方案1】:

    TIKA 并不真正处理页面,但它确实在页面之前发送<div><p> 和在页面之后发送</p></div>。您可以编辑处理程序的 startElementendElement 以搜索这些字符。

    如果您需要更多信息,可以查看topchef 的回答。
    https://stackoverflow.com/a/6271696/2197529

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-13
      • 1970-01-01
      • 2022-06-16
      相关资源
      最近更新 更多