Hye There I am new to this work I am getting this error while compiling my code:
OCR ocr = new OCR();
PDFReader reader = new PDFReader(new File("C:\\Users\\pc\\Downloads\\chk1.pdf"));
reader.open(); // open the file.
int pages = reader.getNumberOfPages();
for(int i=0; i<pages; i++) {
BufferedImage image = reader.getPageAsImage(i); /////null pointer exception here
System.out.println("OCR result:\n" + ocr.recognizeCharacters(image));
}
reader.close(); // finally, close the file.
The error is:
java.lang.NullPointerException
at org.pdfbox.util.operator.pagedrawer.Invoke.a(Unknown Source)
at com.asprise.util.pdf.as.a(Unknown Source)
at com.asprise.util.pdf.as.b(Unknown Source)
at com.asprise.util.pdf.as.a(Unknown Source)
at com.asprise.util.pdf.gV.a(Unknown Source)
at com.asprise.util.pdf.G.l(Unknown Source)
at com.asprise.util.pdf.PDFReader.getPageAsImage(Unknown Source)
at file.tracker.threads.PDFFilerConverter.gotoRead(PDFFilerConverter.java:94)
at file.tracker.threads.PDFFilerConverter.run(PDFFilerConverter.java:60)
at java.lang.Thread.run(Thread.java:744)
Can somebody help me out getting rid out of it please!
try this
for(int i=0; i<pages; i++) {
String txt =reader.extractTextFromPage(i);
System.out.println(“Text result:\n” + txt);
}
Vitalik, which version of the OCR SDK are you using?
I would suggest you try the new Asprise OCR SDK version 5, which should solve your problem. Sample code:
String s = ocr.recognize("C:/test.pdf", -1, 100, 100, 400, 200,
Ocr.RECOGNIZE_TYPE_TEXT, Ocr.OUTPUT_FORMAT_PLAINTEXT);
You may access the download page of Asprise OCR SDK for Java here.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.