OCR command-line tool
Starting in 11.1, Foxit PDF SDK provides a command-line OCR tool on Windows and Linux. Use it to process single pages, whole PDFs, or scanned PDFs to editable formats without integrating the OCR API directly.
For OCR API capabilities, see OCR (Optical Character Recognition). For OCR resource packages and directory layout, see OCR sample setup and run guide.
Use cases
The OCR command-line tool suits:
- Quickly verifying OCR runtime, license, and resource directory setup
- Running OCR from scripts, schedulers, or batch pipelines
- Invoking from Java, Python, C#, Node.js, or other hosts via a separate process
- Outputting scanned PDFs directly as editable formats
How to obtain
Obtain the tool the same way as OCR resources:
- Request a trial or download instructions from the Foxit Developer Hub
- Contact Foxit technical support or sales for the OCR command-line tool package
Prerequisites
Before use, confirm:
- Foxit PDF SDK runtime libraries are deployed correctly
- License files are ready:
gsdk_sn.txt,gsdk_key.txt - OCR engine resource directory is prepared
- The tool executable, SDK dependencies, and license files are in the same working directory
Prepare the run directory
Create a dedicated directory, for example OCRExeTool.
Windows
Place these files in the same directory:
ocr_win64.exefsdk_win64.dllgsdk_sn.txtgsdk_key.txt
Linux x64
Place these files in the same directory:
ocr_linux64libfsdk_linux64.sogsdk_sn.txtgsdk_key.txt
Then view help:
bash
ocr_win64.exe --helpbash
./ocr_linux64 --helpCommand format
Windows:
bash
ocr_win64.exe [options]Linux x64:
bash
./ocr_linux64 [options]Required parameters
| Parameter | Description |
|---|---|
-type | OCR mode: 0 = OCRPDFPage, 1 = OCRPDFDocument, 2 = OCRConvertTo |
-input | Input PDF path |
-output | Output file path |
-engine | OCR engine resource directory path |
Common optional parameters
| Parameter | Description |
|---|---|
-lang | OCR languages, e.g. "English, Chinese-Simplified" |
-edit | Whether output is editable: yes / no |
-pw | Password for the input PDF |
-range | Page range, e.g. 0,2 |
-format | Valid only when -type 2. Output format: 0=DOCX, 1=DOC, 2=RTF, 3=XLSX, 4=XLS, 5=PPTX, 6=HTML |
-type maps to OCR APIs as follows:
0:OCRPDFPage1:OCRPDFDocument2:OCRConvertTo
Image and recognition parameters
These map mainly to OCRConfig:
| Parameter | Description |
|---|---|
-is_detect_pictures | Detect pictures: yes / no |
-is_remove_noise | Denoise: yes / no |
-is_correct_skew | Deskew: yes / no |
-is_enable_text_extraction_mode | Enable text extraction mode |
-is_sequentially_process | Process pages sequentially |
-is_auto_overwrite_resolution | Auto-overwrite resolution |
-resolution_to_overwrite | Manual resolution, e.g. 300 |
-confidence | Confidence threshold, 0-100 |
-ignore_image_width | Minimum width to ignore small images |
-ignore_image_height | Minimum height to ignore small images |
Parameter tips
- Single page:
-type 0 - Whole PDF:
-type 1 - OCR then Word, Excel, PowerPoint, or HTML:
-type 2with-format - Editable output:
-edit yes - Limit pages:
-range - Noisy pages:
-is_remove_noise yes - Skewed pages:
-is_correct_skew yes - Wrong resolution metadata: disable
-is_auto_overwrite_resolutionand set-resolution_to_overwrite - Filter low-confidence results: increase
-confidence
Examples
Windows
bash
ocr_win64.exe -type 0 -input E:/TestFiles/AboutFoxit_ocr.pdf -output E:/TestResult/OCRPDFPage_AboutFoxit_ocr_edit_yes.pdf -engine E:/OCREngine/x64 -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 yes -resolution_to_overwrite 300 -confidence 38 -range 0,2 -ignore_image_width 20 -ignore_image_height 20Linux x64
bash
./ocr_linux64 -type 0 -input /home/test/AboutFoxit_ocr.pdf -output /home/test/result/OCRPDFPage_AboutFoxit_ocr_edit_yes.pdf -engine /opt/OCREngine/x64 -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 yes -resolution_to_overwrite 300 -confidence 38 -range 0,2 -ignore_image_width 20 -ignore_image_height 20Calling from Java
If you do not embed the OCR API, invoke the tool via an external process:
java
import java.io.File;
import java.io.IOException;
public class RunOCRTool {
public static void main(String[] args) {
try {
ProcessBuilder processBuilder = new ProcessBuilder(
"E:\\OCRExeTool\\ocr_win64.exe",
"-type", "0",
"-input", "E:\\TestFiles\\AboutFoxit_ocr.pdf",
"-output", "E:\\TestResult\\OCRPDFPage_AboutFoxit_ocr_edit_yes.pdf",
"-engine", "E:\\OCREngine\\x64",
"-lang", "English",
"-edit", "yes"
);
processBuilder.directory(new File("E:\\OCRExeTool"));
processBuilder.redirectOutput(ProcessBuilder.Redirect.INHERIT);
processBuilder.redirectError(ProcessBuilder.Redirect.INHERIT);
Process process = processBuilder.start();
int exitCode = process.waitFor();
System.out.println("Program execution completed, exit code: " + exitCode);
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
}
}Batch processing tips
- Validate a single file end-to-end before scaling to batch jobs
- Split work by file and let an external scheduler handle concurrency
- Tune concurrency for CPU, memory, and license limits
- Collect stdout, stderr, and exit codes for failed tasks
For in-app batch processing across documents or page ranges, consider OCRPDFDocuments in the OCR API.
Exit codes
| Code | Description |
|---|---|
| 0 | Success |
| 100 | Unknown error |
| 101 | Invalid license |
| 102 | Invalid parameters |
| 103 | GSDK initialization failed |
| 104 | Invalid OCR engine directory |
| 105 | OCR engine initialization failed |
| 106 | Document load failed |
Command-line tool vs OCR API
- Quick runs, scripts, external processes: OCR command-line tool
- Embedded logic, fine-grained callbacks, direct SDK objects: OCR (Optical Character Recognition)
To verify resources, license, and the basic pipeline, run the tool or sample first, then decide whether to integrate the API.