提取的 pdf 文本未显示在控制台中

Extracted pdf text is not getting displayed in console

我正在尝试使用 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

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

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());
}