All Downloads are FREE. Search and download functionalities are using the official Maven repository.

Explore the source code of the class readme.html

    Tess4J - Java Wrapper for Tesseract OCR API




Tess4J is a JNA wrapper for Tesseract OCR API; it provides character recognition support for common image formats, multi-page images, and PDF documents. The library has been developed and tested on Windows and Linux.

Tess4J is released and distributed under the Apache License, v2.0. Its official homepage is at


Java Runtime Environment, JNA, and JAI-ImageIO are required. Apache Maven and JUnit are used for program building and unit testing. The Tesseract DLLs were built with VS2013 and therefore depend on the Visual C++ Redistributable Packages for VS2013.


Tesseract 3.04, Leptonica 1.71 (via Lept4J), and Ghostscript 9.16 32- and 64-bit DLLs, language data for English, and sample images are bundled with the library. Language data packs for Tesseract should be decompressed and placed into the tessdata folder.

The Linux shared object library ( equivalent to the DLL is available in Tesseract 3.04, which can be built from the source with the instructions given in Tesseract Wiki.

To unit test, at the command line, execute:

mvn test

Images to be OCRed should be scanned at resolution from at least 200 DPI (dot per inch) to 400 DPI in monochrome (black&white) or grayscale. Scanning at higher resolutions will not necessarily result in better recognition accuracy. The actual success rates depend greatly on the quality of the scanned image. The typical settings for scanning are 300 DPI and 1 bpp (bit per pixel) black&white or 8 bpp grayscale uncompressed TIFF or PNG format. PNG is usually smaller in size than other image formats and still keeps high quality due to its employing lossless data compression algorithms; TIFF has the advantage of the ability to contain multiple images (pages) in a file.

Several built-in functions are also provided for merging several images or PDF files into a single one for convenient OCR operations, or for splitting a PDF file into smaller ones if it is too large, which can cause out-of-memory exceptions.


The following code example shows common usage of the library. Make sure tessdata folder is populated with appropriate language data files and the .jar files are in the classpath. On Windows, the DLLs will be automatically extracted from tess4j.jar to the default temporary directory and loaded.

package net.sourceforge.tess4j.example;

import net.sourceforge.tess4j.*;

public class TesseractExample {
    public static void main(String[] args) {
        // ImageIO.scanForPlugins(); // for server environment
        File imageFile = new File("eurotext.tif");
        ITesseract instance = new Tesseract(); // JNA Interface Mapping
        // ITesseract instance = new Tesseract1(); // JNA Direct Mapping
        // File tessDataFolder = LoadLibs.extractTessResources("tessdata"); // Maven build only; only English data bundled
        // instance.setDatapath(tessDataFolder.getAbsolutePath());

        try {
            String result = instance.doOCR(imageFile);
        } catch (TesseractException e) {


Please visit the website for the library's documentations