Send comments on this topic. | Back to Introduction - All Topics | Help Version 15.12.21
Recognizing Pages
Take the following steps to start a project and to add some code that demonstrates how to draw pages and zones:
  1. Start with the program you created in Working with Zones .
  2. Drag and drop two buttons in Form1. Leave all the buttons names as the default "button10, button11 ...", then change the following properties of button10:
    PropertyValue
    Text Recognize
  3. Change the following properties of button11:
    PropertyValue
    TextGets Status
  4. Switch to Form1 code view (right-click Form1 in the solution explorer then select View Code ) and add the following code to button10 control’s click procedure::

    [Visual Basic]

    
    Private Sub button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button10.Click
      Try
       ' Set the english as the language for the checking subsystem that will be used for spell checking
       rasterDocument.SpellLanguageId = RasterDocumentLanguage.English
       rasterDocument.EnableSubsystem = True
       rasterDocument.EnableCorrection = True
       
       ' Specifies the name of the file that will be used in the recognition. 
       rasterDocument.RecognitionDataFileName = "c:\testrdf.rdf"
       
       ' Recognize the first page of the RasterDocument object. 
       rasterDocument.Recognize(0, 1, AddressOf RecognizeStatus)
       MessageBox.Show("The engine finished recognizing the specified pages successfully")
       Catch ex As Exception
          MessageBox.Show("Error: " + ex.Message + " in recognized specified pages")
       End Try
       
    End Sub
    
    [C#]
    
    private void button10_Click(object sender, System.EventArgs e)
    {
       try
       {
          // Set the english as the language for the checking subsystem that will be used for spell checking
          rasterDocument.SpellLanguageId = RasterDocumentLanguage.English;
          rasterDocument.EnableSubsystem = true;
          rasterDocument.EnableCorrection = true;
          
          // Specifies the name of the file that will be used in the recognition. 
          rasterDocument.RecognitionDataFileName = @"c:\testrdf.rdf";
          
          // Recognize the first page of the RasterDocument object. 
          rasterDocument.Recognize(0, 1, RecognizeStatus);
          MessageBox.Show("The engine finished recognizing the specified pages successfully");
       }
       catch(Exception ex)
       {
          MessageBox.Show("Error: " + ex.Message + " in recognized specified pages");
       }
    }
    
  5. Add the following code to button11 control’s click procedure:

    [Visual Basic]

    
    Private Sub button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button11.Click
       ' Print some information about the recognition status
       Dim status As RasterDocumentRecognitionStatistic = rasterDocument.RecognitionStatistic
       Dim msg As String
       
       msg = String.Format("Recognition Time = {0}{1}Total Recognized Characters = {2}{3}Total Recognized Words = {4}{5}Total Rejected Characters = {6}{7}Total Rejected Words = {8}", _
                           status.RecognizedTime, Chr(13), _
                           status.RecognizedCharacterCount, Chr(13), _
                           status.RecognizedWordCount, Chr(13), _
                           status.RejectCharacterCount, Chr(13), _
                           status.RejectWordCount)
       
       MessageBox.Show(msg)
    End Sub
    
    [C#]
    
    private void button11_Click(object sender, System.EventArgs e)
    {
       // Print some information about the recognition status
       RasterDocumentRecognitionStatistic status = rasterDocument.RecognitionStatistic;
       string msg;
    
       msg = String.Format("Recognition Time = {0}\nTotal Recognized Characters = {1}\nTotal Recognized Words = {2}\nTotal Rejected Characters = {3}\nTotal Rejected Words = {4}",
                           status.RecognizedTime,
                           status.RecognizedCharacterCount,
                           status.RecognizedWordCount,
                           status.RejectCharacterCount,
                           status.RejectWordCount);
    
       MessageBox.Show(msg);
    }
    
  6. Add the following code to Form1 Class

    [Visual Basic]

    
    Private Function RecognizeStatus(ByVal pageIndex As Integer, ByVal code As RasterDocumentExceptionCode) As Boolean
       Dim msg As String
       msg = String.Format("Recognized page index = {0}{1}Recognition Return value = {2}", _
                           pageIndex, Chr(13), code)
    
       MessageBox.Show(msg)
       Return True
    End Function
    
    [C#]
    
    private bool RecognizeStatus(int pageIndex, RasterDocumentExceptionCode code)
    {
       string msg;
       msg = string.Format("Recognized page index = {0}\nRecognition Return value = {1}",
                                 pageIndex, code);
    
       MessageBox.Show(msg);
       return true;
    }
    
  7. Build and Run the project to test it.
  8. Save this project to be used for testing other code samples.