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

OcrException Class

Example 





Members 
Represents the exception that is thrown when a runtime error occurs inside the IOcrEngine .NET support
Object Model
OcrException Class
Syntax
Remarks

When a runtime error occurs in the IOcrEngine, an exception of type OcrException is thrown with the engine-specific error code set in the Code member. This error code is engine-specific but a short description can be obtained using the System.Exception.Message property of this class or by using the IOcrEngine.GetErrorCodeString method.

Logic errors such as invalid parameters to methods or invalid operations throw standard .NET exceptions (in this case, System.ArgumentException and System.InvalidOperationException respectively Errors caused by loading invalid image files using IOcrEngine.RasterCodecsInstance will throw exceptions of type Leadtools.RasterException. Errors for missing features (support locked) will throw OcrSupportLockedException exceptions. Any other runtime error in the engine will throw an OcrException.

Example
Copy CodeCopy Code  
Public Sub OcrExceptionExample()
      Try
         ' 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)
            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.Recognize(Nothing)

               ' Save the document we have as PDF
               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
      Catch ex As OcrSupportLockedException
         Console.WriteLine("Support is locked. You need to unlock '{0}' in this engine to use this feature", ex.SupportType)
      Catch ex As OcrException
         Console.WriteLine("OCR Error\nCode: {0}\nMessage:{1}", ex.Code, ex.Message)
      Catch ex As RasterException
         Console.WriteLine("LEADTOOLS Error\nCode: {0}\nMessage:{1}", ex.Code, ex.Message)
      Catch ex As Exception
         Console.WriteLine("System Error\nMessage:{0}", ex.Message)
      End Try
   End Sub

Public NotInheritable Class LEAD_VARS
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
public void OcrExceptionExample()
   {
      try
      {
         // 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);
            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.Recognize(null);

               // Save the document we have as 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();
         }
      }
      catch(OcrSupportLockedException ex)
      {
         Console.WriteLine("Support is locked. You need to unlock '{0}' in this engine to use this feature", ex.SupportType);
      }
      catch(OcrException ex)
      {
         Console.WriteLine("OCR Error\nCode: {0}\nMessage:{1}", ex.Code, ex.Message);
      }
      catch(RasterException ex)
      {
         Console.WriteLine("LEADTOOLS Error\nCode: {0}\nMessage:{1}", ex.Code, ex.Message);
      }
      catch(Exception ex)
      {
         Console.WriteLine("System Error\nMessage:{0}", ex.Message);
      }
   }

static class LEAD_VARS
{
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
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

OcrException Members
Leadtools.Forms.Ocr Namespace
IOcrEngine.Startup
IOcrEngine.IsStarted
IOcrEngine.Shutdown
OcrEngineManager Class
OcrEngineType Enumeration
Programming with LEADTOOLS .NET OCR

 

 


Products | Support | Contact Us | Copyright Notices

© 2006-2012 All Rights Reserved. LEAD Technologies, Inc.

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