←Select platform

DocumentWriterInstance Property

Gets the instance of the DocumentWriter object being used inside this IOcrEngine.
public DocumentWriter DocumentWriterInstance { get; } 
@property (nonatomic, strong, readonly) LTDocumentWriter *documentWriterInstance 
public DocumentWriter getDocumentWriterInstance() 
property DocumentWriter^ DocumentWriterInstance { 
   DocumentWriter^ get(); 
DocumentWriterInstance # get  (IOcrEngine) 

Property Value

The DocumentWriter object being used inside this IOcrEngine.


You can pass an instance of an already initialized DocumentWriter object to the Startup method. This DocumentWriter objects will then be used internally by the engine when saving OCR documents to disk or memory. Otherwise, when passing null (Nothing in VB), the IOcrEngine will create and use its own version of DocumentWriter during the startup procedure.

The internal DocumentWriter object will be disposed of by the engine automatically when Shutdown or Dispose is called. If you passed your own instance of DocumentWriter, then the engine will not dispose it and you can continue to use it as normal after the engine instance has been disposed. When passing your own instance of DocumentWriter, make sure this instance stays valid as long as the engine is started.

When new IOcrDocument objects are created using the IOcrDocumentManager.CreateDocument, a new object of type DocumentWriter is created by this IOcrEngine, and assigned to IOcrDocument.DocumentWriterInstance. All document creation operation (such as IOcrDocument.Save) that is performed inside by OCR document or objects inside the OCR document will use that object.

If the value of IOcrDocument.UseEngineInstanceOptions is true, then the options will be copied from the engine's DocumentWriter to the document DocumentWriter before any methods is called.

For more information on how this object is used by the OCR engine during its lifetime, refer to OCR Engine and RasterCodecs/DocumentWriter Usage.


This example shows how to use the DocumentWriterInstance property to modify the save document options before creating the final document. It will set the PDF options to be PDF/A image over text.

using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Ocr; 
using Leadtools.Document.Writer; 
public void DocumentWriterInstanceExample() 
   // Create an instance of the engine 
   using (IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.LEAD)) 
      // Start the engine using default parameters 
      ocrEngine.Startup(null, null, null, LEAD_VARS.OcrLEADRuntimeDir); 
      // You can change the output document options at any time after the engine has 
      // started. Here we will change the PDF options to be PDF/A format with image 
      // over text option turned on 
      // Get the DocumentWriter instance used in this OCR engine 
      DocumentWriter docWriter = ocrEngine.DocumentWriterInstance; 
      // Get the current PDF options, modify and then set it back 
      PdfDocumentOptions pdfOptions = docWriter.GetOptions(DocumentFormat.Pdf) as PdfDocumentOptions; 
      pdfOptions.DocumentType = PdfDocumentType.PdfA; 
      pdfOptions.ImageOverText = true; 
      docWriter.SetOptions(DocumentFormat.Pdf, pdfOptions); 
      // At this point on, every call to IOcrDocument.Save with format equals to DocumentFormat.Pdf will 
      // use the options we set 
      string tifFileName = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.tif"); 
      string pdfFileName = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.pdf"); 
      // Create an OCR document 
      using (IOcrDocument ocrDocument = ocrEngine.DocumentManager.CreateDocument()) 
         // Add a page to the document 
         IOcrPage ocrPage = ocrDocument.Pages.AddPage(tifFileName, null); 
         // Recognize the page 
         // Note, Recognize can be called without calling AutoZone or manually adding zones. The engine will 
         // check and automatically auto-zones the page 
         // Save the document we have as PDF 
         // This will use the options we set earlier (PDF/A with image over text) 
         ocrDocument.Save(pdfFileName, DocumentFormat.Pdf, null); 
      // Shutdown the engine 
      // Note: calling Dispose will also automatically shutdown the engine if it has been started 
static class LEAD_VARS 
   public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images"; 
   public const string OcrLEADRuntimeDir = @"C:\LEADTOOLS22\Bin\Common\OcrLEADRuntime"; 

Target Platforms

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

Leadtools.Ocr Assembly

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