Skip to main content
Developer Guide

Tesseract OCR Libraries
& wrappers.

A working, comparable reference to the libraries and wrappers for every major language — what to install, a minimal example, and the trade-offs between native bindings and CLI wrappers.

On this page

    Which library should I use?

    Pick the row for your language, then read the section below.

    LanguageRecommendedTypeNotes
    PythonpytesseractCLI wrapperSimplest; see the Python guide. Use tesserocr for in-process speed.
    JavaScript / TypeScripttesseract.jsWASMRuns in browser and Node; no PDF support.
    C++TessBaseAPINativeThe core API; maximum control.
    JavaTess4JJNA bindingNeeds the native libraries on the classpath.
    Gogosseractcgo bindingRequires libtesseract-dev.
    C# / .NETTesseract (.NET)Native wrapperNuGet package; bundles Windows binaries only (Linux fix below). Full C# / .NET guide.
    RustleptessNative bindingLinks against Leptonica + Tesseract.
    PHPthiagoalessio/tesseract_ocrCLI wrapperComposer package.

    Python

    The largest ecosystem: a CLI wrapper plus several native bindings.

    • pytesseract — the standard CLI wrapper. Easy, but spawns a process per call.
    • tesserocr — native binding to the C++ API; faster in-process, requires libtesseract-dev.
    • pyocr — a wrapper supporting multiple engines.
    • aiopytesseract — async wrapper for concurrent workloads.
    python
    pip install pytesseract pillow
    import pytesseract
    from PIL import Image
    print(pytesseract.image_to_string(Image.open("image.png")))

    Full walkthrough: Tesseract OCR in Python (pytesseract).

    Video: the same OCR in JavaScript, C#, Java and Go

    Working code in four languages on one receipt, plus the Linux fix for the C# NuGet package, in about 3 minutes.

    3:08 · English narration with on-screen captions

    JavaScript / TypeScript

    tesseract.js brings the engine to the browser and Node through WebAssembly.

    javascript
    npm install tesseract.js
    const Tesseract = require('tesseract.js');
    Tesseract.recognize('image.png', 'eng', { logger: m => console.log(m) })
      .then(({ data: { text } }) => console.log(text));

    Note: tesseract.js does not support PDF files and does not modify the recognition model. For Node-only use, node-tesseract-ocr wraps the installed CLI instead.

    C++

    The native TessBaseAPI is the reference integration and what most bindings wrap.

    ocr.cpp
    #include <tesseract/baseapi.h>
    #include <leptonica/allheaders.h>
    
    tesseract::TessBaseAPI* api = new tesseract::TessBaseAPI();
    api->Init(NULL, "eng");
    Pix* image = pixRead("image.png");
    api->SetImage(image);
    char* text = api->GetUTF8Text();
    printf("%s", text);
    api->End(); pixDestroy(&image);

    Build against libtesseract-dev and libleptonica-dev (see installation).

    Java

    Tess4J is the mature JNA wrapper; JavaCPP presets are an alternative.

    Ocr.java
    // Maven: net.sourceforge.tess4j:tess4j
    import net.sourceforge.tess4j.Tesseract;
    Tesseract t = new Tesseract();
    t.setDatapath("tessdata");
    String text = t.doOCR(new java.io.File("image.png"));

    Go

    gosseract uses cgo to link against the Tesseract C++ library.

    main.go
    go get github.com/otiai10/gosseract/v2
    import "github.com/otiai10/gosseract/v2"
    client := gosseract.NewClient()
    defer client.Close()
    client.SetImage("image.png")
    text, _ := client.Text()

    Requires libtesseract-dev and libleptonica-dev (Linux) or the Homebrew packages (macOS).

    C# / .NET

    The Tesseract NuGet package wraps the native library and ships the Windows binaries.

    Program.cs
    // dotnet add package Tesseract
    using Tesseract;
    using var engine = new TesseractEngine(@"./tessdata", "eng", EngineMode.Default);
    using var img = Pix.LoadFromFile("image.png");
    using var page = engine.Process(img);
    Console.WriteLine(page.GetText());

    On Linux the same code throws DllNotFoundException: Failed to find library "libleptonica-1.82.0.so", because the package (5.2.0) only bundles Windows DLLs. Install the system libraries and link them under the names the package looks for (paths for Ubuntu/Debian x64; tested with .NET 8):

    bash
    sudo apt install -y libtesseract5 liblept5
    dotnet build
    ln -s /usr/lib/x86_64-linux-gnu/liblept.so.5 bin/Debug/net8.0/x64/libleptonica-1.82.0.so
    ln -s /usr/lib/x86_64-linux-gnu/libtesseract.so.5 bin/Debug/net8.0/x64/libtesseract50.so
    ln -s /usr/lib/x86_64-linux-gnu/libdl.so.2 bin/Debug/net8.0/libdl.so   # glibc 2.34+ ships only libdl.so.2
    dotnet run

    Package comparison, an automatic .csproj fix, thread-safe ASP.NET Core use and accuracy and speed measurements are in the C# / .NET guide.

    Other languages

    Community bindings exist for most ecosystems.

    • Rust — leptess (native binding), rusty-tesseract (CLI wrapper).
    • PHP — thiagoalessio/tesseract_ocr (Composer, CLI wrapper).
    • Ruby — rtesseract (CLI wrapper).
    • C — the Tesseract C API (tesseract/capi.h).

    CLI wrapper vs native binding

    The choice matters more than the language for performance.

    FactorCLI wrapperNative binding
    SetupEasy — just install the engineNeeds dev headers/libraries
    Speed per callSlower (process per call)Faster (in-process)
    ControlCLI flags and config onlyFull API (iterators, boxes, confidence)
    Examplespytesseract, rtesseract, node-tesseract-ocrtesserocr, Tess4J, gosseract, TessBaseAPI

    For one-off scripts, a CLI wrapper is usually the fastest path. For high-volume or latency-sensitive services, prefer a native binding or batch through the CLI (see the performance notes).

    Libraries FAQ

    Which Tesseract library should I use?

    Match the row in the table above to your language. Use a native binding for speed and control, a CLI wrapper for simplicity.

    Do I need the engine installed separately?

    Yes for most wrappers — they rely on the installed Tesseract engine and language data. Only tesseract.js bundles a WebAssembly build of the engine.

    Does tesseract.js support PDFs?

    No. It recognises images; convert PDF pages to images first, or use a library that adds PDF support.

    Which is fastest?

    Native in-process bindings such as tesserocr, Tess4J and gosseract avoid per-call process startup. For CLI wrappers, batch pages and use multiprocessing.

    Install the engine, then pick your language.