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
OCRmodule - 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:
- Continuous trial use is allowed for 30 days from the first initialization of
OCREngine. - During the trial period, the total number of PDF pages processed by OCR must not exceed 5,000.
- 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/ocrdirectory. 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:
- Create an OCR resource directory for the sample (the merged directory passed to
OCREngine.initialize), for exampleD:/ocr_runtime(this is a different path fromocr_resourcesextracted in the previous section; the steps below copy files fromocr_resourcesinto this directory). - Copy the appropriate library files from
ocr_resourcesinto 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.
- 32-bit systems: copy all files from
- Copy the required language resources (also from
ocr_resourcesinto 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.
- CJK languages only: copy all files from
- (Optional) Debug mode: copy files from
ocr_resources/debugging_files/win32orocr_resources/debugging_files/win64into the resource directory created in step 1.
Linux x64 steps:
- 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 matchLD_LIBRARY_PATHbelow). - Copy the
DataandBindirectories fromocr_resources_linuxinto the resource directory created in step 1. - Set the
LD_LIBRARY_PATHenvironment 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.initializeto the resource directory path. - Set languages: Use
OCREngine.setLanguagesto set recognition languages. English is the default. - (Optional) Set a log file: Uncomment
OCREngine.setLogFileto 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.