←Select platform

OcrEngine Property

Summary

Optional OCR engine instance to use when extracting text.

Syntax
C#
C++/CLI
Java
Python
public IOcrEngine OcrEngine { get; set; } 
public:  
   property IOcrEngine^ OcrEngine 
   { 
      IOcrEngine^ get() 
      void set(IOcrEngine^ value) 
   } 
public OcrEngine getOcrEngine() 
public void setOcrEngine(OcrEngine value) 
OcrEngine # get and set (DocumentText) 

Property Value

The optional OCR engine instance to use when extracting text. Default value is null.

Remarks

This property is not used if the value of TextExtractionMode is DocumentTextExtractionMode.SvgOnly.

The text of the document can be extracted using OCR technologies, in this mode, a valid IOcrEngine instance must be initialized (created and started) and set in the OcrEngine property before DocumentPage.GetText is called.

OcrEngine can be setup with any extra options from outside (such as enable languages, spell checker, accuracy tradeoffs, etc.). The Document class will use the engine as is.

The Document object will not delete the value of OcrEngine when it is disposed. IOcrEngine is thread-safe by nature and the same instance can be set into multiple Document instances and used at the same time.

For more information, refer to Parsing Text with the Document Library.

Note that setting this property to a value will update the same value in each child document.

Example
C#
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Document.Writer; 
 
using Leadtools.Document; 
using Leadtools.Caching; 
using Leadtools.Annotations.Engine; 
using Leadtools.Ocr; 
using Leadtools.Barcode; 
using Leadtools.Document.Converter; 
 
public void DocumentTextExample() 
{ 
   var options = new LoadDocumentOptions(); 
   using (var document = DocumentFactory.LoadFromFile(Path.Combine(LEAD_VARS.ImagesDir, "slice.tif"), options)) 
   { 
      //for the TIF file we need an OCR engine 
      var ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.LEAD); 
      var rasterCodecs = new RasterCodecs(); 
      var documentWriter = new DocumentWriter(); 
      ocrEngine.Startup(rasterCodecs, documentWriter, null, LEAD_VARS.OcrLEADRuntimeDir); 
 
      // DocumentText reference 
      document.Text.OcrEngine = ocrEngine; 
 
      // Get all of the DocumentTextExtractionModes (DocumentTextExtractionMode reference) 
      DocumentTextExtractionMode[] textExtractionModes = (DocumentTextExtractionMode[])Enum.GetValues(typeof(DocumentTextExtractionMode)); 
      foreach (var modes in textExtractionModes) 
      { 
         Console.WriteLine($"Text extraction mode: {modes}"); 
      } 
 
      // get text  
      var page = document.Pages[0]; 
      var pageText = page.GetText(); 
      if (pageText != null) 
      { 
         pageText.BuildText(); 
         var text = pageText.Text; 
 
         Console.WriteLine(text); 
      } 
      else 
      { 
         Console.WriteLine("Failed!"); 
      } 
   } 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images"; 
   public const string OcrLEADRuntimeDir = @"C:\LEADTOOLS22\Bin\Common\OcrLEADRuntime"; 
} 
Requirements

Target Platforms

Help Version 22.0.2023.4.21
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Document Assembly

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.