Leadtools.Document Requires Document/Medical product license | Send comments on this topic. | Back to Introduction - All Topics | Help Version 15.10.31
GetRecognizedCharacters Method
See Also  Example
Leadtools.Document Namespace > RasterDocumentEngine Class : GetRecognizedCharacters Method




pageIndex
Specifies the index of the recognized page for which to get the recognized characters. This is a zero-based index
Gets all of the characters that have been recognized for a specific page.

Syntax

Visual Basic (Declaration) 
Public Function GetRecognizedCharacters( _
   ByVal pageIndex As Integer _
) As IList(Of RasterDocumentRecognizedCharacters)
Visual Basic (Usage)Copy Code
Dim instance As RasterDocumentEngine
Dim pageIndex As Integer
Dim value As IList(Of RasterDocumentRecognizedCharacters)
 
value = instance.GetRecognizedCharacters(pageIndex)
C# 
public IList<RasterDocumentRecognizedCharacters> GetRecognizedCharacters( 
   int pageIndex
)
Managed Extensions for C++ 
public: IList<RasterDocumentRecognizedCharacters>* GetRecognizedCharacters( 
   int pageIndex
) 
C++/CLI 
public:
IList<RasterDocumentRecognizedCharacters>^ GetRecognizedCharacters( 
   int pageIndex
) 

Parameters

pageIndex
Specifies the index of the recognized page for which to get the recognized characters. This is a zero-based index

Return Value

An array of RasterDocumentRecognizedCharacters objects which contains all recognized characters in the specified page

Example

Visual BasicCopy Code
Public Sub GetRecognizedCharactersExample()
   ' Note that this is a sample key, which will not work in your toolkit
   RasterSupport.Unlock(Leadtools.RasterSupportType.Ocr, "TestKey")

   Dim rasterDocument As RasterDocumentEngine
   rasterDocument = RasterDocumentEngine.Instance
   rasterDocument.Startup()
   'assume page is added, refer to AddPage example for more information

   rasterDocument.SpellLanguageId = RasterDocumentLanguage.English
   rasterDocument.RecognitionDataFileName = "C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\test.rdf"

   rasterDocument.Recognize(0, 1, Nothing)

   Dim recognizedChars As IList(Of RasterDocumentRecognizedCharacters) = rasterDocument.GetRecognizedCharacters(0)
   Dim font As RasterDocumentFontFlags
   Dim i As Integer = 0
   Do While i < recognizedChars.Count
      If recognizedChars(i).Confidence > 900 Then
         Dim tmpChar As RasterDocumentRecognizedCharacters = recognizedChars(i)
         font = tmpChar.Font

         font = font Or RasterDocumentFontFlags.Bold Or RasterDocumentFontFlags.Underline
         tmpChar.Font = font
         tmpChar.FontSize = 20

         If (tmpChar.Flags And RasterDocumentCharacterPositionFlags.EndOfWord) = RasterDocumentCharacterPositionFlags.EndOfWord Then
            Dim buffer As String

            buffer = String.Format("Last Character in the word is available at the following position" & Constants.vbLf & "Left = {0}" & Constants.vbLf & "Top = {1}" & Constants.vbLf & "Width = {2}" & Constants.vbLf & "Height = {3}" & Constants.vbLf & "YOffset = {4}", recognizedChars(i).Rectangle.Left, recognizedChars(i).Rectangle.Top, recognizedChars(i).Rectangle.Width, recognizedChars(i).Rectangle.Height, recognizedChars(i).YOffset)
            MessageBox.Show(buffer)

            buffer = String.Format("First guess char = {0}" & Constants.vbLf & "Second guess char = {1}" & Constants.vbLf & "Third guess char = {2}", recognizedChars(i).GuessCode, recognizedChars(i).GuessCode2, recognizedChars(i).GuessCode3)
            MessageBox.Show(buffer)

            buffer = String.Format("First Language Id = {0}" & Constants.vbLf & "Second Language Id = {1}" & Constants.vbLf & "Zone Index = {2}" & Constants.vbLf & "Cell Index = {3}" & Constants.vbLf & "Space = {4}" & Constants.vbLf & "Space Error = {5}", recognizedChars(i).LanguageId2, recognizedChars(i).LanguageId2, recognizedChars(i).ZoneIndex, recognizedChars(i).CellIndex, recognizedChars(i).Space, recognizedChars(i).SpaceError)
            MessageBox.Show(buffer)
         End If

         recognizedChars(i) = tmpChar
      End If
      i += 1
   Loop

   rasterDocument.SetRecognizedCharacters(0, recognizedChars)
   Dim resultOpts As RasterDocumentResultOptions = rasterDocument.SaveResultOptions

   resultOpts.Format = RasterDocumentFormatType.RtfWord2000
   resultOpts.FormatLevel = RasterDocumentFormatLevel.Full

   Dim docOpts As RasterDocumentOptions
   docOpts = resultOpts.Document
   docOpts.PaperSizeMode = RasterDocumentSelector.Predefined
   docOpts.PaperType = RasterDocumentPaperType.A4
   docOpts.PaperOrientation = RasterDocumentPaperOrientation.Portrait
   docOpts.RetainGraphics = RasterDocumentRetainGraphicsMode.Original
   docOpts.TextInboxes = False
   docOpts.Margins = New Rectangle(5, 5, 195, 195)
   docOpts.RetainPageBreaks = True
   docOpts.TableMethod = RasterDocumentTableMethod.UseTabs

   resultOpts.Document = docOpts
   rasterDocument.SaveResultOptions = resultOpts
   rasterDocument.SaveResultsToFile("C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\Test.doc")

   rasterDocument.Shutdown()
End Sub
C#Copy Code
public void GetRecognizedCharactersExample() 

   //  Note that this is a sample key, which will not work in your toolkit 
   RasterSupport.Unlock(RasterSupportType.Ocr, "TestKey"); 
   RasterDocumentEngine rasterDocument; 
   rasterDocument = RasterDocumentEngine.Instance; 
   rasterDocument.Startup(); 
 
   // assume page is added, refer to AddPage example for more information 
 
   rasterDocument.SpellLanguageId = RasterDocumentLanguage.English; 
   rasterDocument.RecognitionDataFileName = @"C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\test.rdf"; 
 
   rasterDocument.Recognize(0, 1, null); 
 
   IList<RasterDocumentRecognizedCharacters> recognizedChars  = rasterDocument.GetRecognizedCharacters(0); 
   RasterDocumentFontFlags font; 
   for(int i = 0; i < recognizedChars.Count; i++) 
   { 
      if (recognizedChars[i].Confidence > 900) 
      { 
         RasterDocumentRecognizedCharacters tmpChar = recognizedChars[i]; 
         font = tmpChar.Font; 
 
         font |= RasterDocumentFontFlags.Bold | RasterDocumentFontFlags.Underline; 
         tmpChar.Font = font; 
         tmpChar.FontSize = 20; 
 
         if ((tmpChar.Flags & RasterDocumentCharacterPositionFlags.EndOfWord) == RasterDocumentCharacterPositionFlags.EndOfWord) 
         { 
            string buffer; 
 
            buffer = String.Format("Last Character in the word is available at the following position\nLeft = {0}\nTop = {1}\nWidth = {2}\nHeight = {3}\nYOffset = {4}", recognizedChars[i].Rectangle.Left, recognizedChars[i].Rectangle.Top, recognizedChars[i].Rectangle.Width, recognizedChars[i].Rectangle.Height, recognizedChars[i].YOffset); 
            MessageBox.Show(buffer); 
 
            buffer = String.Format("First guess char = {0}\nSecond guess char = {1}\nThird guess char = {2}", recognizedChars[i].GuessCode, recognizedChars[i].GuessCode2, recognizedChars[i].GuessCode3); 
            MessageBox.Show(buffer); 
 
            buffer = String.Format("First Language Id = {0}\nSecond Language Id = {1}\nZone Index = {2}\nCell Index = {3}\nSpace = {4}\nSpace Error = {5}", recognizedChars[i].LanguageId2, recognizedChars[i].LanguageId2, recognizedChars[i].ZoneIndex, recognizedChars[i].CellIndex, recognizedChars[i].Space, recognizedChars[i].SpaceError); 
            MessageBox.Show(buffer); 
         } 
 
         recognizedChars[i] = tmpChar; 
      } 
   } 
 
   rasterDocument.SetRecognizedCharacters(0, recognizedChars); 
   RasterDocumentResultOptions resultOpts = rasterDocument.SaveResultOptions; 
 
   resultOpts.Format = RasterDocumentFormatType.RtfWord2000; 
   resultOpts.FormatLevel = RasterDocumentFormatLevel.Full; 
 
   RasterDocumentOptions docOpts; 
   docOpts = resultOpts.Document; 
   docOpts.PaperSizeMode = RasterDocumentSelector.Predefined; 
   docOpts.PaperType = RasterDocumentPaperType.A4; 
   docOpts.PaperOrientation = RasterDocumentPaperOrientation.Portrait; 
   docOpts.RetainGraphics = RasterDocumentRetainGraphicsMode.Original; 
   docOpts.TextInboxes = false; 
   docOpts.Margins = new Rectangle(5, 5, 195, 195); 
   docOpts.RetainPageBreaks = true; 
   docOpts.TableMethod = RasterDocumentTableMethod.UseTabs; 
 
   resultOpts.Document = docOpts; 
   rasterDocument.SaveResultOptions = resultOpts; 
   rasterDocument.SaveResultsToFile(@"C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\Test.doc"); 
 
   rasterDocument.Shutdown(); 
}

Remarks

This method will return an array for all recognized characters for the specified recognized page.
This method can be called after a successful recognition process started by calling Recognize.
This method should not be called before calling Recognize.
To update the recognized characters, call Generic SetRecognizedCharacters.
To save the updated recognized characters to a file, call SaveResultsToFile.
Also, To save the results into memory, call SaveResultsToMemory.
For more information, refer to Recognizing Document Pages.
For more information, refer to Confidence Reporting.

Requirements

Target Platforms: Microsoft .NET Framework 2.0, Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

Leadtools.Documentrequires a Document or Medical toolkit license and unlock key. For more information, refer to: Raster Pro/Document/Medical Features