PDFBox在pdf java中搜索值

问题描述 投票:0回答:1

我正在尝试在Java中使用PDFBox,并成功检索了我所有的pdf。但是现在我希望搜索一个特定的单词,只检索以下数字。具体来说,我想搜索Tax并检索作为tax的数字。这两个字符串似乎用制表符分隔。

我的代码如下atm

  File file = new File("yes.pdf");
try {
     PDDocument document = PDDocument.load(file);
     PDFTextStripper pdfStripper = new PDFTextStripper();

String text = pdfStripper.getText(document);

System.out.println(text);

// search for the word tax
// retrieve the number af the word "Tax"

document.close();
}
java pdfbox
1个回答
0
投票

执行类似操作的最佳方法是使用正则表达式。我经常使用this tool编写正则表达式。您的正则表达式可能看起来像:tax\s([0-9]+)。您可以看看this tutorial如何在Java中使用正则表达式。

© www.soinside.com 2019 - 2024. All rights reserved.