public static String doOCR(File pdfInvoice) {
String result = "";
long totalTime = 0;
long endTime = 0;
long startTime = System.currentTimeMillis();
File imageFile = new File("D:\\docfolder\\9011121584.pdf");
Tesseract instance = Tesseract.getInstance(); //
try {
ImageIO.scanForPlugins();
result = instance.doOCR(imageFile);
endTime = System.currentTimeMillis();
totalTime = endTime - startTime;
System.out.println("Total Time Taken For OCR: " + (totalTime / 1000));
return result;
} catch (Exception e) {
System.err.println(e.getMessage());
result = "";
return result;
}
}
加入ImageIO.scanForPlugins();这段代码,最终解决问题
本文介绍了一个使用 Tesseract 实现的 PDF 文档光学字符识别 (OCR) 方法,并通过加入 ImageIO.scanForPlugins() 代码解决了相关问题。该方法能够读取 PDF 文件并将其转换为文本,同时记录 OCR 处理的总耗时。
1万+

被折叠的 条评论
为什么被折叠?



