【问题标题】:Parsing PDF to HTML using PDF2DOM returns null使用 PDF2DOM 将 PDF 解析为 HTML 返回 null
【发布时间】:2017-10-23 01:57:54
【问题描述】:

我正在使用pdf2dom 并尝试他们的基本文档。在他们的文档中声明 - Pdf2Dom 基于 Apache PDFBox™ 库。

File file = new File("file.pdf");
PDDocument pdf = PDDocument.load(file);
PDFDomTree parser = new PDFDomTree();
Document dom = parser.createDOM(pdf);
System.out.println(dom);

打印出来的内容 - [#document: null]

用 3 个不同的 pdf 尝试了相同的代码

当我在文本中剥离相同的 PDF 时,它会返回有效文本。因此该文件不为空。我做错了什么还是图书馆本身?

脱衣舞代码如果有帮助的话。

PDDocument pdf = PDDocument.load(pFile);
PDFTextStripper stripper = new PDFTextStripper();
String text = stripper.getText(pd);
System.out.println(text);

任何建议将不胜感激,在此先感谢。

【问题讨论】:

    标签: java html pdf dom


    【解决方案1】:

    您的代码没有任何问题。 Document 对象的 toString() 方法以这种方式返回。

    [#document: null],由两部分组成。 第一部分是#document,它是节点名称。解析 XML 时,您总是会收到一个 #document 节点作为顶级节点。 第二部分为null,即节点的值。 null 用于表示该节点没有值。

    如果您打印dom.getDocumentElement().getTextContent(),那么您应该会看到一些价值。

    【讨论】:

    • 谢谢,对于菜鸟的错误感到抱歉
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-24
    • 2013-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多