LEADTOOLS OCR (Leadtools.Forms.Ocr assembly)
LEAD Technologies, Inc

DocumentWriterInstance Property (IOcrEngine)

Example 





Gets the instance of the Leadtools.Forms.DocumentWriters.DocumentWriter object being used inside this IOcrEngine. .NET support WinRT support
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 CodeCopy Code  
Public Sub DocumentWriterInstanceExample()
      ' Create an instance of the engine
      Using ocrEngine As IOcrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Plus, False)
         ' Start the engine using default parameters
         ocrEngine.Startup(Nothing, Nothing, Nothing, Nothing)
         ' 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"
End Class
public void DocumentWriterInstanceExample()
   {
      // Create an instance of the engine
      using(IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Plus, false))
      {
         // Start the engine using default parameters
         ocrEngine.Startup(null, null, null, null);
         // 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";
}
[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: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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-2012 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