我正在尝试使用 AsposePdf 在 PDF 文件中搜索字符串。
这就是我正在做的事情:
String path = "C:/Windows/Fonts";
List list = Document.getLocalFontPaths();
list.add(path);
Document.setLocalFontPaths(list);
Document pdfDocument = new Document("myFile.pdf");
PageCollection pages = pdfDocument.getPages();
TextAbsorber textAbsorber = new TextAbsorber
(new TextExtractionOptions(TextExtractionOptions.TextFormattingMode.Raw));
for(int i = 1; i <= pages.size(); i++){
Page currentPage = pdfDocument.getPages().get_Item(i);
currentPage.accept(textAbsorber);
String abText = textAbsorber.getText();
String[] abArray = abText.trim().split("\n");
for (String txtArray : abArray) {
if (txtArray.contains("SomeText")) {
//do something
}
}
}
NullPointerException 在:currentPage.accept(textAbsorber);
错误堆栈跟踪:
java.lang.NullPointerException
at com.aspose.pdf.internal.p51.z11.m2(Unknown Source)
at com.aspose.pdf.internal.p51.z11.m7(Unknown Source)
at com.aspose.pdf.internal.p51.z13.m1(Unknown Source)
at com.aspose.pdf.internal.p51.z13.m1(Unknown Source)
at com.aspose.pdf.internal.p51.z13.m6(Unknown Source)
at com.aspose.pdf.internal.p51.z13.<init>(Unknown Source)
at com.aspose.pdf.internal.p51.z13.<init>(Unknown Source)
at com.aspose.pdf.TextAbsorber.visit(Unknown Source)
at com.aspose.pdf.Page.accept(Unknown Source)
可能是什么原因?