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.

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 native binaries.
RustleptessNative bindingLinks against Leptonica + Tesseract.
PHPthiagoalessio/tesseract_ocrCLI wrapperComposer package.

Python

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

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).

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 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());

Other languages

Community bindings exist for most ecosystems.

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.