←Select platform

DocumentWriterInstance Property

Summary
Gets the instance of the DocumentWriter object being used inside this IOcrEngine.
Syntax
C#
Objective-C
C++/CLI
Java
Python
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.

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#
Java
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 
         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:\LEADTOOLS23\Resources\Images"; 
   public const string OcrLEADRuntimeDir = @"C:\LEADTOOLS23\Bin\Common\OcrLEADRuntime"; 
} 
 
import java.io.File; 
import java.io.IOException; 
import java.nio.file.Files; 
import java.nio.file.Path; 
import java.nio.file.Paths; 
 
import org.junit.*; 
import org.junit.runner.JUnitCore; 
import org.junit.runner.Result; 
import org.junit.runner.notification.Failure; 
import static org.junit.Assert.assertTrue; 
 
import leadtools.*; 
import leadtools.codecs.*; 
import leadtools.document.writer.*; 
import leadtools.ocr.*; 
 
 
public void IOcrDocumentWriterInstanceExample() { 
   final String OCR_LEAD_RUNTIME_DIR = "C:\\LEADTOOLS23\\Bin\\Common\\OcrLEADRuntime"; 
   final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images"; 
 
   // Create an instance of the engine 
   OcrEngine ocrEngine = OcrEngineManager.createEngine(OcrEngineType.LEAD); 
 
   // Start the engine using default parameters 
   ocrEngine.startup(null, null, null, OCR_LEAD_RUNTIME_DIR); 
   assertTrue(ocrEngine.isStarted()); 
 
   // Get the DocumentWriter instance used in this OCR engine 
   DocumentWriter docWriter = ocrEngine.getDocumentWriterInstance(); 
 
   // Get the current PDF options, modify and then set it back 
   PdfDocumentOptions pdfOptions = (PdfDocumentOptions) docWriter.getOptions(DocumentFormat.PDF); 
 
   pdfOptions.setDocumentType(PdfDocumentType.PDFA); 
   pdfOptions.setImageOverText(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 pdfFileName = combine(LEAD_VARS_IMAGES_DIR, "Ocr1.pdf"); 
   ILeadStream leadStream = LeadStreamFactory.create("C:\\LEADTOOLS23\\Resources\\Images\\Ocr1.tif"); 
 
   // Create an OCR document 
   OcrDocument ocrDocument = ocrEngine.getDocumentManager().createDocument(); 
   // Add a page to the document 
   OcrPage ocrPage = ocrDocument.getPages().addPage(leadStream, 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(); 
 
   assertTrue("File was unsuccessfully saved.", new File(pdfFileName).exists()); 
   System.out.println("File was saved correctly."); 
} 
Requirements

Target Platforms

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

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