←Select platform

DocumentWriterInstance Property

Summary

Gets the instance of the DocumentWriter object being used inside this IOcrEngine.

Syntax
C#
VB
Objective-C
C++
Java
public DocumentWriter DocumentWriterInstance { get; } 
ReadOnly Property DocumentWriterInstance As DocumentWriter 
@property (nonatomic, strong, readonly) LTDocumentWriter *documentWriterInstance 
public DocumentWriter getDocumentWriterInstance() 
property DocumentWriter^ DocumentWriterInstance { 
   DocumentWriter^ get(); 
} 

Property Value

The DocumentWriter object being used inside this IOcrEngine.

Remarks

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.

Example

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.

C#
VB
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, false)) 
   { 
      // 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 
         ocrPage.AutoZone(null); 
         ocrPage.Recognize(null); 
 
         // 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 
      ocrEngine.Shutdown(); 
   } 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images"; 
   public const string OcrLEADRuntimeDir = @"C:\LEADTOOLS 20\Bin\Common\OcrLEADRuntime"; 
} 
Imports Leadtools 
Imports Leadtools.Codecs 
Imports Leadtools.Ocr 
Imports Leadtools.Document.Writer 
 
Public Sub DocumentWriterInstanceExample() 
   ' Create an instance of the engine 
   Using ocrEngine As IOcrEngine = OcrEngineManager.CreateEngine(OcrEngineType.LEAD, False) 
      ' Start the engine using default parameters 
      ocrEngine.Startup(Nothing, Nothing, Nothing, 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 
      Dim docWriter As DocumentWriter = ocrEngine.DocumentWriterInstance 
 
      ' Get the current PDF options, modify and then set it back 
      Dim pdfOptions As PdfDocumentOptions = TryCast(docWriter.GetOptions(DocumentFormat.Pdf), 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 
 
      Dim tifFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.tif") 
      Dim pdfFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.pdf") 
 
      ' Create an OCR document 
      Using ocrDocument As IOcrDocument = ocrEngine.DocumentManager.CreateDocument() 
         ' Add a page to the document 
         Dim ocrPage As IOcrPage = ocrDocument.Pages.AddPage(tifFileName, Nothing) 
 
         ' 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 
         ocrPage.AutoZone(Nothing) 
         ocrPage.Recognize(Nothing) 
 
         ' 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, Nothing) 
      End Using 
 
      ' Shutdown the engine 
      ' Note: calling Dispose will also automatically shutdown the engine if it has been started 
      ocrEngine.Shutdown() 
   End Using 
End Sub 
 
Public NotInheritable Class LEAD_VARS 
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images" 
   Public Const OcrLEADRuntimeDir As String = "C:\LEADTOOLS 20\Bin\Common\OcrLEADRuntime" 
End Class 

Requirements

Target Platforms

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

Leadtools.Ocr Assembly