Skip to content

OCR Sample: Configuration and Run Guide

Optical character recognition (OCR) is a technology that converts printed or handwritten text in images into machine-readable text. It is widely used in document digitization, data extraction, and automated workflows, significantly improving information processing efficiency.

Foxit PDF SDK provides powerful OCR capabilities on Windows and Linux x64, with ongoing updates and optimizations to the OCR engine. The resource directory setup below applies to all languages listed in the table; the step-by-step run instructions focus on the Java sample on Windows. If you use Java on Linux x64, complete the Linux resource directory and LD_LIBRARY_PATH configuration described in this guide, then set the resource path in the sample code for Linux. For other languages, open the corresponding simple_demo/ocr (or equivalent) sample in the SDK package and use the same resource directory structure.

To learn about OCR capabilities, key APIs, and use cases first, see OCR (Optical Character Recognition). To run OCR tasks directly from the command line, see OCR Command Tool.

System Requirements

  • Platforms: Windows, Linux x64
  • Languages: C, C++, Java, Python, C#
  • License: A license key that includes the OCR module
  • SDK versions:
    • Foxit PDF SDK for Windows (C++, Java, C#) 6.4+
    • Foxit PDF SDK (C) 7.4+
    • Foxit PDF SDK for Windows (Python) 8.3+
    • Foxit PDF SDK for Linux x64 (C++, Java, C#, Python) 9.0+

The versions above are the minimum SDK versions that first introduced OCR for each listed language. Refer to the package documentation and release notes for the latest versions and platform differences.

Trial Limitations

If you use a Foxit PDF SDK trial license key, you do not need to license the OCR engine library separately, but the following limitations apply:

  1. Continuous trial use is allowed for 30 days from the first initialization of OCREngine.
  2. During the trial period, the total number of PDF pages processed by OCR must not exceed 5,000.
  3. All PDF pages processed by OCR during the trial include a trial watermark.

Obtaining the OCR Resource Package

  • Request a trial through the Foxit Developer Hub, or contact your Foxit technical support team and sales representatives to obtain the OCR resource package.

OCR Resource Directory Overview

Windows

Extract the Windows resource package to a directory (for example, ocr_resources; this name refers to the extraction root directory throughout this guide). The root directory contains the following folders and files:

  • debugging_files: Resource files for debugging the OCR engine. Do not distribute these with your application.
  • language_resource_CJK: Language resources for Simplified Chinese, Traditional Chinese, Japanese, and Korean.
  • language_resources_noCJK: Resources for other supported languages, such as English, French, and German.
  • win32_lib/win64_lib: Library files for 32-bit and 64-bit systems, respectively.
  • readme.txt: Instructions for organizing and using the resource files.

Linux x64

Extract the Linux x64 resource package to a directory (for example, ocr_resources_linux; this name refers to the extraction root directory throughout this guide). The root directory contains:

  • Data: Data and resources for all supported languages.
  • Bin: Linux x64 library files.

Sample Run Guide

Sample location:

  • The OCR sample is located in the /examples/simple_demo/ocr directory. The configuration and run instructions below use the Java library as an example.

Build the OCR Resource Directory

Before running the OCR sample, build an OCR resource directory and pass the full directory path to OCREngine.initialize.

Windows steps:

  1. Create an OCR resource directory for the sample (the merged directory passed to OCREngine.initialize), for example D:/ocr_runtime (this is a different path from ocr_resources extracted in the previous section; the steps below copy files from ocr_resources into this directory).
  2. Copy the appropriate library files from ocr_resources into the resource directory created in step 1 based on the target platform:
    • 32-bit systems: copy all files from ocr_resources/win32_lib.
    • 64-bit systems: copy all files from ocr_resources/win64_lib.
  3. Copy the required language resources (also from ocr_resources into the resource directory created in step 1):
    • CJK languages only: copy all files from ocr_resources/language_resource_CJK.
    • Non-CJK languages only: copy all files from ocr_resources/language_resources_noCJK.
    • All languages: copy all files from both directories above.
  4. (Optional) Debug mode: copy files from ocr_resources/debugging_files/win32 or ocr_resources/debugging_files/win64 into the resource directory created in step 1.

Linux x64 steps:

  1. Create an OCR resource directory for the sample (the merged directory passed to OCREngine.initialize), for example /opt/ocr_runtime (you can also use a writable path such as ~/ocr_runtime; it must match LD_LIBRARY_PATH below).
  2. Copy the Data and Bin directories from ocr_resources_linux into the resource directory created in step 1.
  3. Set the LD_LIBRARY_PATH environment variable (replace the path with your resource directory): export LD_LIBRARY_PATH=/opt/ocr_runtime/Bin

Configure the Sample

Configure the sample in /examples/simple_demo/ocr/ocr.java.

Linux x64 (Java): As on Windows, set the argument to OCREngine.initialize to the absolute path of the OCR resource directory you built locally. Ensure LD_LIBRARY_PATH is configured as described above before running; otherwise, native libraries may fail to load.

  • Specify the OCR resource directory: Set the argument to OCREngine.initialize to the resource directory path.
  • Set languages: Use OCREngine.setLanguages to set recognition languages. English is the default.
  • (Optional) Set a log file: Uncomment OCREngine.setLogFile to enable logging.

Run the Sample

After a successful run, the console displays relevant output and the following PDF documents are generated in /examples/simple_demo/output_files/ocr:

  • ocr_doc_editable.pdf: Editable OCR PDF document.
  • ocr_doc_searchable.pdf: Searchable OCR PDF document.
  • ocr_page_editable.pdf: Editable OCR PDF page.
  • ocr_page_searchable.pdf: Searchable OCR PDF page.

By following these steps, you can configure and run the Foxit PDF SDK OCR sample and experience its OCR capabilities.