我有一个 PDF 文件,想从中提取文本。我正在使用 PDFTextStream。我从它的文档中得到了这段代码,但它给出了错误。
import com.snowtide.PDF;
import com.snowtide.pdf.Document;
import com.snowtide.pdf.OutputTarget;
public class ExtractText {
public static void main (String[] args) throws java.io.IOException {
// String pdfFilePath = args[0];
Document pdf = PDF.open("data/bill.pdf");
StringBuilder text = new StringBuilder(1024);
pdf.pipe(new OutputTarget(text));
pdf.close();
System.out.println(text);
}
}
这是错误:
Exception in thread "main" java.lang.NullPointerException
at com.snowtide.pdf.e.b(SourceFile:2740)
at com.snowtide.pdf.e.a(SourceFile:2691)
at com.snowtide.pdf.e.c(SourceFile:2642)
at com.snowtide.pdf.e.a(SourceFile:2059)
at com.snowtide.pdf.e.c(SourceFile:2108)
at com.snowtide.pdf.e.a(SourceFile:1950)
at com.snowtide.pdf.e.a(SourceFile:1755)
at com.snowtide.pdf.e.a(SourceFile:1820)
at com.snowtide.pdf.e.pipe(SourceFile:468)
at ExtractText.main(ExtractText.java:12)
我正在使用 PDFTextStream 3.3.1 版。第 12 行是这样的:
pdf.pipe(new OutputTarget(text));