GSDK v11 的 OCR 能力通过独立的ocr_win64.exe工具支持多进程。由于该工具为可执行程序,多进程场景下可通过同时启动多个ocr_win64.exe实例实现(每个实例独立处理任务),需注意为每个进程分配独立的输入 / 输出路径,避免文件冲突。
使用步骤如下:
准备目录与文件:创建OCRExeTool目录,将gsdk_key.txt、gsdk_sn.txt、fsdk_win64.dll(从foxitpdfsdk_*_win.zip包中获取)及ocr_win64.exe拷贝至该目录;
查看参数说明:执行命令 ocr_win64.exe --help 可获取所有支持的参数及用法;
执行 OCR 任务:通过 Java 调用 OCR exe 工具,示例:
可通过ProcessBuilder类启动ocr_win64.exe进程,示例代码框架如下:
public static void main(String[] args) {
try {
ProcessBuilder processBuilder = new ProcessBuilder();
// Set commands and parameters
processBuilder.command(
"C:\\Users\\yang_leng\\Desktop\\exe\\ocr_win64.exe"
,"-type","0"
,"-input","C:\\Users\\yang_leng\\Desktop\\2.pdf"
,"-output","C:\\Users\\yang_leng\\Desktop\\2_OCR.pdf"
,"-engine","C:\\Users\\yang_leng\\Desktop\\SDKProject\\GSDK\\ocr_addon\\Res_OCR_V12_5_15_0_V11_0_win (2)\\win64_lib"
,"-lang","English"
,"-edit","yes"
,"-is_detect_pictures","yes"
,"-is_remove_noise","yes"
,"-is_correct_skew","yes"
,"-is_enable_text_extraction_mode","yes"
,"-is_sequentially_process","yes"
,"-is_auto_overwrite_resolution","false"
,"-resolution_to_overwrite","300"
,"-confidence","38"
,"-range","0,2" //页码 范围
,"-ignore_image_width","20"
,"-ignore_image_height","20");
// Set the working directory
processBuilder.directory(new File("C:\\Users\\yang_leng\\Desktop\\exe"));
// Redirect input and output
processBuilder.redirectOutput(ProcessBuilder.Redirect.INHERIT);
processBuilder.redirectError(ProcessBuilder.Redirect.INHERIT);
// start process
Process process = processBuilder.start();
// Obtain output stream (if data needs to be input into the program)
OutputStream outputStream = process.getOutputStream();
// Waiting for the process to complete
int exitCode = process.waitFor();
System.out.println("Program execution completed, exit code:" + exitCode);
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
}
}
OCR exe 工具执行后返回的错误码代的含义:
(1)成功: 0
(2)未知错误: 100
(3)License无效: 101
(4)参数错误: 102
(5)GSDK初始化失败: 103
(6)OCR引擎目录错误: 104
(7)OCR引擎初始化失败: 105
(8)文档加载失败: 106