LEADTOOLS OCR (Leadtools.Forms.Ocr assembly)

DocumentWriterInstance Property (IOcrEngine)

Show in webframe
Example 







Gets the instance of the Leadtools.Forms.DocumentWriters.DocumentWriter object being used inside this IOcrEngine.
Syntax
DocumentWriter DocumentWriterInstance {get;}
'Declaration
 
ReadOnly Property DocumentWriterInstance As DocumentWriter
'Usage
 
Dim instance As IOcrEngine
Dim value As DocumentWriter
 
value = instance.DocumentWriterInstance
DocumentWriter DocumentWriterInstance {get;}

            

            
get_DocumentWriterInstance(); 
property DocumentWriter^ DocumentWriterInstance {
   DocumentWriter^ get();
}

Property Value

The Leadtools.Forms.DocumentWriters.DocumentWriter object being used inside this IOcrEngine.
Remarks

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

The internal Leadtools.Forms.DocumentWriters.DocumentWriter object will be disposed of by the engine automatically when Shutdown or System.IDisposable.Dispose is called. If you passed your own instance of Leadtools.Forms.DocumentWriters.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 Leadtools.Forms.DocumentWriters.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 Leadtools.Forms.DocumentWriters.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 Leadtools.Forms.DocumentWriters.DocumentWriter to the document Leadtools.Forms.DocumentWriters.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
Copy Code  
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.Forms.Ocr
Imports Leadtools.Forms
Imports Leadtools.Forms.DocumentWriters
Imports Leadtools.WinForms

Public Sub DocumentWriterInstanceExample()
   ' Create an instance of the engine
   Using ocrEngine As IOcrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Advantage, False)
      ' Start the engine using default parameters
      ocrEngine.Startup(Nothing, Nothing, Nothing, LEAD_VARS.OcrAdvantageRuntimeDir)
      ' 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 = DirectCast(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 OcrAdvantageRuntimeDir As String = "C:\LEADTOOLS 18\Bin\Common\OcrAdvantageRuntime"
End Class
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Forms.Ocr;
using Leadtools.Forms.DocumentWriters;

public void DocumentWriterInstanceExample()
{
   // Create an instance of the engine
   using (IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Advantage, false))
   {
      // Start the engine using default parameters
      ocrEngine.Startup(null, null, null, LEAD_VARS.OcrAdvantageRuntimeDir);
      // 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 OcrAdvantageRuntimeDir = @"C:\LEADTOOLS 18\Bin\Common\OcrAdvantageRuntime";
}
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Forms.Ocr;
using Leadtools.Forms.DocumentWriters;

[TestMethod]
public async Task DocumentWriterInstanceExample()
{
   // Create an instance of the engine
   IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Advantage, false);
   // Start the engine using default parameters
   ocrEngine.Startup(null, null, String.Empty, Tools.OcrEnginePath);

   // 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.SaveAsunc with format equals to DocumentFormat.Pdf will
   // use the options we set

   string tifFileName = @"Assets\Ocr1.tif";
   string pdfFileName = "Ocr1.pdf";

   // Create an OCR document
   IOcrDocument ocrDocument = ocrEngine.DocumentManager.CreateDocument();

   // Add a page to the document
   IOcrPage ocrPage = null;
   using (RasterCodecs codecs = new RasterCodecs())
   {
      StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(tifFileName);
      using (RasterImage image = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile)))
      {
         ocrPage = ocrDocument.Pages.AddPage(image, 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)
   StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync(pdfFileName, CreationCollisionOption.ReplaceExisting);
   await ocrDocument.SaveAsync(LeadStreamFactory.Create(saveFile), DocumentFormat.Pdf, null);

   // Shutdown the engine
   ocrEngine.Shutdown();
}
Requirements

Target Platforms

See Also

Reference

IOcrEngine Interface
IOcrEngine Members
Startup
IsStarted Property
Shutdown Method
OcrEngineManager Class
OcrEngineType Enumeration
Programming with the LEADTOOLS .NET OCR

 

 


Products | Support | Contact Us | Copyright Notices
© 2006-2014 All Rights Reserved. LEAD Technologies, Inc.

DocumentWriterInstance requires an OCR module license and unlock key. For more information, refer to: Imaging Pro/Document/Medical Features