Skip to content

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.exe
  • fsdk_win64.dll
  • gsdk_sn.txt
  • gsdk_key.txt

Linux x64

Place these files in the same directory:

  • ocr_linux64
  • libfsdk_linux64.so
  • gsdk_sn.txt
  • gsdk_key.txt

Then view help:

bash
ocr_win64.exe --help
bash
./ocr_linux64 --help

Command format

Windows:

bash
ocr_win64.exe [options]

Linux x64:

bash
./ocr_linux64 [options]

Required parameters

ParameterDescription
-typeOCR mode: 0 = OCRPDFPage, 1 = OCRPDFDocument, 2 = OCRConvertTo
-inputInput PDF path
-outputOutput file path
-engineOCR engine resource directory path

Common optional parameters

ParameterDescription
-langOCR languages, e.g. "English, Chinese-Simplified"
-editWhether output is editable: yes / no
-pwPassword for the input PDF
-rangePage range, e.g. 0,2
-formatValid 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: OCRPDFPage
  • 1: OCRPDFDocument
  • 2: OCRConvertTo

Image and recognition parameters

These map mainly to OCRConfig:

ParameterDescription
-is_detect_picturesDetect pictures: yes / no
-is_remove_noiseDenoise: yes / no
-is_correct_skewDeskew: yes / no
-is_enable_text_extraction_modeEnable text extraction mode
-is_sequentially_processProcess pages sequentially
-is_auto_overwrite_resolutionAuto-overwrite resolution
-resolution_to_overwriteManual resolution, e.g. 300
-confidenceConfidence threshold, 0-100
-ignore_image_widthMinimum width to ignore small images
-ignore_image_heightMinimum height to ignore small images

Parameter tips

  • Single page: -type 0
  • Whole PDF: -type 1
  • OCR then Word, Excel, PowerPoint, or HTML: -type 2 with -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_resolution and 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 20

Linux 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 20

Calling 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

CodeDescription
0Success
100Unknown error
101Invalid license
102Invalid parameters
103GSDK initialization failed
104Invalid OCR engine directory
105OCR engine initialization failed
106Document load failed

Command-line tool vs OCR API

To verify resources, license, and the basic pipeline, run the tool or sample first, then decide whether to integrate the API.