# TesseractOcrEngine class

> OCR with an installed Tesseract: each image is one tesseract process that reads the pixels from its standard input and writes its results to its...

Namespace: [PdfNetStack.Ocr.Tesseract](https://www.jadev-corp.com/api/pdfnetstack-ocr-tesseract/)  
Assembly: PdfNetStack.Ocr.Tesseract.dll  
Package: `PdfNetStack`

OCR with an installed Tesseract: each image is one <code>tesseract</code> process that reads the pixels
from its standard input and writes its results to its standard output, with no shell and no
temporary files. A process that crashes, hangs or floods its output only costs that image.
Safe to call from several threads, up to [MaxConcurrentProcesses](https://www.jadev-corp.com/api/pdfnetstack-ocr-tesseract/tesseractocrengineoptions/#PdfNetStack_Ocr_Tesseract_TesseractOcrEngineOptions_MaxConcurrentProcesses)
at once. Tesseract and its language data are installed separately.

```csharp
public sealed class TesseractOcrEngine : IOcrEngine, IDisposable
```

**Inheritance**

[object](https://learn.microsoft.com/dotnet/api/system.object) ← 
[TesseractOcrEngine](https://www.jadev-corp.com/api/pdfnetstack-ocr-tesseract/tesseractocrengine/)

**Implements**

[IOcrEngine](https://www.jadev-corp.com/api/pdfnetstack-ocr/iocrengine/), 
[IDisposable](https://learn.microsoft.com/dotnet/api/system.idisposable)

## Examples

<pre><code class="lang-csharp">using var engine = TesseractOcrEngine.Load(new TesseractOcrEngineOptions { Languages = ["fra+ara"] });
var report = new PdfOcr(engine, new PdfOcrOptions { Languages = ["fra+ara"] }).MakeSearchable(document);</code></pre>

## Properties

### <a id="PdfNetStack_Ocr_Tesseract_TesseractOcrEngine_InstalledLanguages"></a> InstalledLanguages

The languages Tesseract has data for, as it names them.

```csharp
public IReadOnlyCollection<string> InstalledLanguages { get; }
```

#### Property Value

 [IReadOnlyCollection](https://learn.microsoft.com/dotnet/api/system.collections.generic.ireadonlycollection\-1)<[string](https://learn.microsoft.com/dotnet/api/system.string)\>

### <a id="PdfNetStack_Ocr_Tesseract_TesseractOcrEngine_Version"></a> Version

The version the executable reports, such as <code>5.5.0</code>.

```csharp
public string Version { get; }
```

#### Property Value

 [string](https://learn.microsoft.com/dotnet/api/system.string)

## Methods

### <a id="PdfNetStack_Ocr_Tesseract_TesseractOcrEngine_Dispose"></a> Dispose\(\)

Refuses new calls, and ends those waiting for their turn with `ObjectDisposedException`.
A process already running is not stopped: its call finishes with its real result or failure,
within [Timeout](https://www.jadev-corp.com/api/pdfnetstack-ocr-tesseract/tesseractocrengineoptions/#PdfNetStack_Ocr_Tesseract_TesseractOcrEngineOptions_Timeout). To stop one sooner, cancel its token.

```csharp
public void Dispose()
```

### <a id="PdfNetStack_Ocr_Tesseract_TesseractOcrEngine_Load_PdfNetStack_Ocr_Tesseract_TesseractOcrEngineOptions_"></a> Load\(TesseractOcrEngineOptions?\)

Finds Tesseract, checks its version and that the data for [Languages](https://www.jadev-corp.com/api/pdfnetstack-ocr-tesseract/tesseractocrengineoptions/#PdfNetStack_Ocr_Tesseract_TesseractOcrEngineOptions_Languages) is there.

```csharp
public static TesseractOcrEngine Load(TesseractOcrEngineOptions? options = null)
```

#### Parameters

`options` [TesseractOcrEngineOptions](https://www.jadev-corp.com/api/pdfnetstack-ocr-tesseract/tesseractocrengineoptions/)?

Where things are, and tuning; defaults when null.

#### Returns

 [TesseractOcrEngine](https://www.jadev-corp.com/api/pdfnetstack-ocr-tesseract/tesseractocrengine/)

#### Exceptions

 [FileNotFoundException](https://learn.microsoft.com/dotnet/api/system.io.filenotfoundexception)

The executable or the data for a language is missing. The message says where to get it.

 [DirectoryNotFoundException](https://learn.microsoft.com/dotnet/api/system.io.directorynotfoundexception)

[TessdataPath](https://www.jadev-corp.com/api/pdfnetstack-ocr-tesseract/tesseractocrengineoptions/#PdfNetStack_Ocr_Tesseract_TesseractOcrEngineOptions_TessdataPath) does not exist.

 [ArgumentException](https://learn.microsoft.com/dotnet/api/system.argumentexception)

A language name or a setting is not valid.

 [TesseractOcrException](https://www.jadev-corp.com/api/pdfnetstack-ocr-tesseract/tesseractocrexception/)

The executable fails, or is not Tesseract 4 or later.

### <a id="PdfNetStack_Ocr_Tesseract_TesseractOcrEngine_Recognize_PdfNetStack_Ocr_OcrBitmap_PdfNetStack_Ocr_OcrRequest_System_Threading_CancellationToken_"></a> Recognize\(OcrBitmap, OcrRequest, CancellationToken\)

Recognizes one upright 8 bit gray image; boxes come back in its pixel coordinates.

```csharp
public OcrImageResult Recognize(OcrBitmap image, OcrRequest request, CancellationToken cancellationToken)
```

#### Parameters

`image` [OcrBitmap](https://www.jadev-corp.com/api/pdfnetstack-ocr/ocrbitmap/)

The image, text upright.

`request` [OcrRequest](https://www.jadev-corp.com/api/pdfnetstack-ocr/ocrrequest/)

The script to read.

`cancellationToken` [CancellationToken](https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken)

Stops the work between lines.

#### Returns

 [OcrImageResult](https://www.jadev-corp.com/api/pdfnetstack-ocr/ocrimageresult/)

#### Exceptions

 [ArgumentException](https://learn.microsoft.com/dotnet/api/system.argumentexception)

The language is not installed or not valid, or the image is larger than Tesseract reads.

 [TimeoutException](https://learn.microsoft.com/dotnet/api/system.timeoutexception)

The process took longer than [Timeout](https://www.jadev-corp.com/api/pdfnetstack-ocr-tesseract/tesseractocrengineoptions/#PdfNetStack_Ocr_Tesseract_TesseractOcrEngineOptions_Timeout) and was killed.

 [TesseractOcrException](https://www.jadev-corp.com/api/pdfnetstack-ocr-tesseract/tesseractocrexception/)

The process failed, or its output cannot be used.

 [OperationCanceledException](https://learn.microsoft.com/dotnet/api/system.operationcanceledexception)

Cancelled; the process was killed.

 [ObjectDisposedException](https://learn.microsoft.com/dotnet/api/system.objectdisposedexception)

The engine was disposed before this call's process started.

## Used in

- [Make scanned PDFs searchable with OCR in C#](https://www.jadev-corp.com/guides/ocr/)

Source: https://www.jadev-corp.com/pdfnetstack/api/pdfnetstack-ocr-tesseract/tesseractocrengine/
