←Select platform

IOcrTableZoneManager Interface

Summary

Represents an Object used to manipulate cells inside a table zone.

Syntax

C#
VB
C++
public interface IOcrTableZoneManager 

Public Interface IOcrTableZoneManager  

public interface class IOcrTableZoneManager  

Remarks

You can access the IOcrTableZoneManager of an OCR page through the IOcrPage.TableZoneManager property. If the value of this property is null (Nothing in VB), then the current OCR engine does not support table cell manipulation.

You can use table cells in one of two ways:

  • Perform auto-zoning on the page using IOcrPage.AutoZone, if the page contains a detected table, the a zone of type OcrZoneType.Table is created for this table. If the engine successfully detects the cells of the table, then it will fill the an internal OcrZoneCell array with the properties of the detected cells.

  • Manually add a new OcrZone with its type set to OcrZoneType.Table to the zones collection of a page. Leave the value of the cells to null (Nothing in VB), now use the IOcrTableZoneManager.AutoDetectCells method to instruct the engine to detect any cells in this zone and fill the array with the data.

To manipulate a cell properties other than its bound (OcrZoneCell.Bounds), get the array of detected cells through IOcrZoneCollection.GetZoneCells, change the cell background color, style or any border color, style or with. When you are done, re-set the array using IOcrZoneCollection.SetZoneCells.

It is not recommended that you manually remove or add cells to the array, the engine is very sensitive to zone boundaries and any non-accurate information will cause an error. Instead, use the various methods of IOcrTableZoneManager to manipulate the cell location and size.

Manipulating cells position and size inside a table zone is a very sensitive matter and any non-accurate information will cause an error. The IOcrTableZoneManager contains methods to easily accomplish these tasks with minimum error. These methods are built around what is expected to be accomplished by an application that manipulates the cells of a zone through a user-interface, such as clicking and dragging with the mouse.

The following methods can be used to manipulate the cells position and size:

  • SplitCells and merge cells to split/merge the cells inside a given area in a table zone. This makes it easy to add/remove cells to the zone.

  • GetPointInformation to Gets the cell index and the nearest border for a given point. This can be used by selecting a cell or a border using a mouse click.

  • MoveCellBorder and GetCellBorderDragLimit to move a cell border while making sure it does not get run over adjacent cells or the table area. This can be used to change the size of a cell by clicking and dragging the mouse.

  • GetTabulatorPosition to get the tabulator position. The tabulator has only a horizontal position.

  • GetHorizontalSplitters and GetVerticalSplitters to get the number and positions of horizontal and vertical splitters. You can these methods to draw splitter guidelines in your user interface, or change the mouse cursor to a different shape if it is located over a splitter and dragging is allowed.

Example

C#
VB
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Forms.Common; 
using Leadtools.Ocr; 
using Leadtools.Drawing; 
 
private static void IOcrTableZoneManageExample(IOcrEngine ocrEngine, string documentFileName) 
{ 
   // Create a document and add the page to it 
   using (IOcrPage ocrPage = ocrEngine.CreatePage(ocrEngine.RasterCodecsInstance.Load(documentFileName, 1), OcrImageSharingMode.AutoDispose)) 
   { 
      // The coordinate for the table has been previously determined: 
      LeadRect tableBounds = new LeadRect(266, 554, 404, 647); 
 
      // Add a table zone with these bounds 
      OcrZone zone = new OcrZone(); 
      zone.ZoneType = OcrZoneType.Table; 
      zone.Bounds = tableBounds; 
      ocrPage.Zones.Add(zone); 
 
      if (ocrPage.TableZoneManager != null) 
      { 
         // Detect the cells inside this table 
         IOcrTableZoneManager ocrTableZoneManager = ocrPage.TableZoneManager; 
         ocrTableZoneManager.AutoDetectCells(0); 
      } 
 
      // Show the cells for this zone (if any) 
      zone = ocrPage.Zones[0]; 
 
      Console.WriteLine("Detected values:"); 
      ShowCells(ocrPage, zone); 
 
      // Change the style of the first cell to have no borders 
      OcrZoneCell[] cells = ocrPage.Zones.GetZoneCells(zone); 
      if (cells != null && cells.Length > 0) 
      { 
         OcrZoneCell cell = cells[0]; 
         cell.LeftBorderStyle = OcrCellBorderLineStyle.None; 
         cell.TopBorderStyle = OcrCellBorderLineStyle.None; 
         cell.RightBorderStyle = OcrCellBorderLineStyle.None; 
         cell.BottomBorderStyle = OcrCellBorderLineStyle.None; 
         cells[0] = cell; 
      } 
 
      ocrPage.Zones.SetZoneCells(zone, cells); 
 
      Console.WriteLine("Updated values:"); 
      ShowCells(ocrPage, zone); 
   } 
} 
 
private static void ShowCells(IOcrPage ocrPage, OcrZone zone) 
{ 
   OcrZoneCell[] cells = ocrPage.Zones.GetZoneCells(zone); 
   if (cells != null) 
   { 
      Console.WriteLine("Table contains {0} zones", cells.Length); 
 
      for (int i = 0; i < cells.Length; i++) 
      { 
         Console.WriteLine("  Cell {0}:", i); 
 
         OcrZoneCell cell = cells[i]; 
         Console.WriteLine("    Type: {0}", cell.CellType); 
         Console.WriteLine("    Bounds: {0}", cell.Bounds); 
         Console.WriteLine("    Background color: {0}", cell.BackgroundColor); 
         Console.WriteLine("    Left border color: {0}", cell.LeftBorderColor); 
         Console.WriteLine("    Left border width: {0}", cell.LeftBorderWidth); 
         Console.WriteLine("    Left border style: {0}", cell.LeftBorderStyle); 
         Console.WriteLine("    Top border color: {0}", cell.TopBorderColor); 
         Console.WriteLine("    Top border width: {0}", cell.TopBorderWidth); 
         Console.WriteLine("    Top border style: {0}", cell.TopBorderStyle); 
         Console.WriteLine("    Right border color: {0}", cell.RightBorderColor); 
         Console.WriteLine("    Right border width: {0}", cell.RightBorderWidth); 
         Console.WriteLine("    Right border style: {0}", cell.RightBorderStyle); 
         Console.WriteLine("    Bottom border color: {0}", cell.BottomBorderColor); 
         Console.WriteLine("    Bottom border width: {0}", cell.BottomBorderWidth); 
         Console.WriteLine("    Bottom border style: {0}", cell.BottomBorderStyle); 
      } 
   } 
} 

Imports Leadtools 
Imports Leadtools.Codecs 
Imports Leadtools.Forms 
Imports Leadtools.Ocr 
Imports Leadtools.Drawing 
 
Public Sub IOcrTableZoneManageExample(ocrEngine As IOcrEngine, documentFileName As String) 
   ' Create a document and add the page to it 
   Using ocrPage As IOcrPage = ocrEngine.CreatePage(ocrEngine.RasterCodecsInstance.Load(documentFileName, 1), OcrImageSharingMode.AutoDispose) 
      ' The coordinate for the table has been previously determined: 
      Dim tableBounds As New LeadRect(266, 554, 404, 647) 
 
      ' Add a table zone with these bounds 
      Dim zone As New OcrZone() 
      zone.ZoneType = OcrZoneType.Table 
      zone.Bounds = tableBounds 
      ocrPage.Zones.Add(zone) 
 
      ' Detect the cells inside this table 
      Dim ocrTableZoneManager As IOcrTableZoneManager = ocrPage.TableZoneManager 
      ocrTableZoneManager.AutoDetectCells(0) 
 
      ' Show the cells for this zone (if any) 
      zone = ocrPage.Zones(0) 
 
      Console.WriteLine("Detected values:") 
      ShowCells(ocrPage, zone) 
 
      ' Change the style of the first cell to have no borders 
      Dim cells As OcrZoneCell() = ocrPage.Zones.GetZoneCells(zone) 
      If cells IsNot Nothing AndAlso cells.Length > 0 Then 
         Dim cell As OcrZoneCell = cells(0) 
         cell.LeftBorderStyle = OcrCellBorderLineStyle.None 
         cell.TopBorderStyle = OcrCellBorderLineStyle.None 
         cell.RightBorderStyle = OcrCellBorderLineStyle.None 
         cell.BottomBorderStyle = OcrCellBorderLineStyle.None 
         cells(0) = cell 
      End If 
 
      ocrPage.Zones.SetZoneCells(zone, cells) 
 
      Console.WriteLine("Updated values:") 
      ShowCells(ocrPage, zone) 
   End Using 
End Sub 
 
Private Shared Sub ShowCells(ocrPage As IOcrPage, zone As OcrZone) 
   Dim cells As OcrZoneCell() = ocrPage.Zones.GetZoneCells(zone) 
   If cells IsNot Nothing Then 
      Console.WriteLine("Table contains {0} zones", cells.Length) 
 
      For i As Integer = 0 To cells.Length - 1 
         Console.WriteLine("  Cell {0}:", i) 
 
         Dim cell As OcrZoneCell = cells(i) 
         Console.WriteLine("    Type: {0}", cell.CellType) 
         Console.WriteLine("    Bounds: {0}", cell.Bounds) 
         Console.WriteLine("    Background color: {0}", cell.BackgroundColor) 
         Console.WriteLine("    Left border color: {0}", cell.LeftBorderColor) 
         Console.WriteLine("    Left border width: {0}", cell.LeftBorderWidth) 
         Console.WriteLine("    Left border style: {0}", cell.LeftBorderStyle) 
         Console.WriteLine("    Top border color: {0}", cell.TopBorderColor) 
         Console.WriteLine("    Top border width: {0}", cell.TopBorderWidth) 
         Console.WriteLine("    Top border style: {0}", cell.TopBorderStyle) 
         Console.WriteLine("    Right border color: {0}", cell.RightBorderColor) 
         Console.WriteLine("    Right border width: {0}", cell.RightBorderWidth) 
         Console.WriteLine("    Right border style: {0}", cell.RightBorderStyle) 
         Console.WriteLine("    Bottom border color: {0}", cell.BottomBorderColor) 
         Console.WriteLine("    Bottom border width: {0}", cell.BottomBorderWidth) 
         Console.WriteLine("    Bottom border style: {0}", cell.BottomBorderStyle) 
      Next 
   End If 
End Sub 

Requirements

Target Platforms

Help Version 20.0.2018.6.20
Products | Support | Contact Us | Copyright Notices
© 1991-2018 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Ocr Assembly