←Select platform

WorkDirectory Property

Summary
Gets the path to the work directory used by this IOcrEngine to store the engine temporary files.
Syntax
C#
Objective-C
C++/CLI
Java
Python
public string WorkDirectory { get; } 
@property (nonatomic, copy, readonly, nullable) NSString *workDirectory 
public String getWorkDirectory() 
property String^ WorkDirectory { 
   String^ get(); 
} 
WorkDirectory # get  (IOcrEngine) 

Property Value

The path to the work directory used by this IOcrEngine to store the engine temporary files.

Remarks

The WorkDirectory is passed as the workDirectory parameter to the Startup method. This directory is used when the engine saves the its temporary files. The IOcrEngine object will create various temporary files during recognition and document saving processes. It will use the path passed in WorkDirectory as the location where these temporary files will be created. You can pass null (Nothing in VB) to let the engine select the temporary directory of the current logged in user (TEMP).

In either case, the value of working directory of the current started IOcrEngine can be obtained through the WorkDirectory property.

The engine will automatically deletes any temporary files created. However, if an unexpected error occurs (for example, an unhandled exception), some temporary files may still reside in the work directory after the application exits. A typical application may use a custom directory inside the application path and manually deletes any files that may reside there before calling Startup in case the previous instance of the application exited abnormally.

If the value of WorkDirectory is not null (Nothing in VB), then it must refer to a valid directory that exists in the system and the process that created the engine must have access rights to read, write and delete files from this directory.

The value WorkDirectory will hold the current work directory used by the OCR engine, if you passed null (Nothing in VB) in the Startup method, the value of this property will be set to the current logged in user TEMP value.

Example
C#
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Ocr; 
using Leadtools.Document.Writer; 
 
public void StartupEngineExample() 
{ 
   // Use RasterCodecs to load an image file 
   // Note: You can let the engine load the image file directly as shown in the other examples 
   RasterCodecs codecs = new RasterCodecs(); 
   RasterImage image = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.tif")); 
 
   // Assume you copied the engine runtime files to C:\MyApp\Ocr 
   string engineDir = @"C:\MyApp\Ocr"; 
 
   // Store the engine work directory into a path inside our application 
   string workDir = @"C:\MyApp\OcrTemp"; 
 
   // Delete all files in the work directory in case the previous version of our application exited abnormally and 
   // the engine did not get the chance to clean all of its temporary files (if any) 
   Directory.Delete(workDir, true); 
 
   // Re-create the work directory 
   Directory.CreateDirectory(workDir); 
 
   // Create an instance of the engine 
   using (IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.LEAD)) 
   { 
      // Show that the engine has not been started yet 
      Console.WriteLine("Before calling Startup, IsStarted = " + ocrEngine.IsStarted); 
 
      // Start the engine using our parameters 
      // Since we already have a RasterCodecs object, we can re-use it to save memory and resources 
      ocrEngine.Startup(codecs, null, workDir, engineDir); 
 
      // Make sure the engine is using our working directory 
      Console.WriteLine("workDir passed is {0}, the value of WorkDirectory after Startup is {1}", workDir, ocrEngine.WorkDirectory); 
 
      // Show that the engine has started fine 
      Console.WriteLine("After calling Startup, EngineType is {0}, IsStarted = {1}", ocrEngine.EngineType, ocrEngine.IsStarted); 
 
      // Maks sure the engine is using our own version of RasterCodecs 
      Debug.Assert(codecs == ocrEngine.RasterCodecsInstance); 
 
      // Create a page from the raster image as page to the document 
      IOcrPage ocrPage = ocrEngine.CreatePage(image, OcrImageSharingMode.AutoDispose); 
      // image belongs to the page and will be dispose when the page is disposed 
 
      // 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.Recognize(null); 
 
      // Create a file based document 
      using (IOcrDocument ocrDocument = ocrEngine.DocumentManager.CreateDocument(null, OcrCreateDocumentOptions.AutoDeleteFile)) 
      { 
         // Add the page 
         ocrDocument.Pages.Add(ocrPage); 
         // No need for the page anymore 
         ocrPage.Dispose(); 
 
         // Save the document we have as PDF 
         string pdfFileName = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.pdf"); 
         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:\LEADTOOLS22\Resources\Images"; 
} 
Requirements

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.