I have a PDF file and want to extract text from it. I am using PDFTextStream. I got this code from its documentation, but it gives error.
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);
}
}
This is the error:
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)
I am using PDFTextStream version 3.3.1. Line 12 is this:
pdf.pipe(new OutputTarget(text));
The Pdf file should be corrupted or something... there is no way to reproduce the error. Try with another pdf file