【问题标题】:Extracted pdf text is not getting displayed in console提取的 pdf 文本未显示在控制台中
【发布时间】:2019-06-18 04:20:59
【问题描述】:

我正在尝试使用 Tabula 提取 pdf 文本。但是代码没有错误,但是当我运行提取的 pdf 文本时,控制台中没有显示。有人能帮忙吗。

我一直在使用 PDFBox,在做了一些研究后,我发现 tabula 是新的并想尝试一下。

File file = new File(pdfFilePath);
PDDocument document = PDDocument.load(file);
ObjectExtractor oe = new ObjectExtractor(document);
Page page = oe.extract(1) //1st page
TextStripper textStripper = new TextStripper(document,1);
System.out.println(textStripper.getText(document));

output of pdf text

【问题讨论】:

  • 可能 PDF 不支持文本提取。尝试用 Adob​​e Reader 打开它,然后复制和粘贴。

标签: java tabula


【解决方案1】:

您没有使用页面变量。试试下面的代码。

File file = new File(pdfFilePath);
PDDocument document = PDDocument.load(file);
ObjectExtractor oe = new ObjectExtractor(document);
Page page = oe.extract(1); // 1st page

for (TextElement textElement: page.getText()) {
  System.out.print(textElement.getText());
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-01-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-13
    • 1970-01-01
    • 2017-06-13
    相关资源
    最近更新 更多