Send comments on this topic. | Back to Introduction - All Topics | Help Version 15.12.21
Working with Recognition Results
Take the following steps to add code to the existing project that will let you deal with the OCR Recognition Results:
  1. Start with the program you created in Recognizing Pages.
  2. Drag and drop two buttons in Form1. Leave all the buttons names as the default "button12, button13 ...", then change the following properties of button12:
    PropertyValue
    TextGet Output Format
  3. Change the following properties of button13:
    PropertyValue
    TextSave Document
  4. Add the following code to button12 control’s click procedure:

    [Visual Basic]

     
    Private Sub button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button12.Click
       Try
          ' Start an enumeration through all the available file formats
          Dim formatType As RasterDocumentFormatType() = rasterDocument.AvailableOutputFileFormats()
          Dim i As Integer
    
          For i = 0 To formatType.Length - 1
             Dim fileInfo As RasterDocumentFileFormatInfo
             fileInfo = rasterDocument.GetTextFormatInfo(formatType(i))
    
             ' Print some information about the current format
             MessageBox.Show("Format Name = " + fileInfo.FormatName + Chr(13) + _
                             "Format DLL Name = " + fileInfo.DllName + Chr(13) + _
                             "Format Ext = " + fileInfo.ExtensionName + Chr(13) + _
                             "Format Type = " + fileInfo.Type.ToString())
          Next
       Catch
       End Try
    End Sub
    
    [C#]
     
    private void button12_Click(object sender, System.EventArgs e)
    {
       // Start an enumeration through all the available file formats
       try
       {
          RasterDocumentFormatType[] formatType = rasterDocument.AvailableOutputFileFormats();
    
          for (int i = 0; i < formatType.Length; i++)
          {
             RasterDocumentFileFormatInfo fileInfo;
             fileInfo = rasterDocument.GetTextFormatInfo(formatType[i]);
    
             // Print some information about the current format
             MessageBox.Show("Format Name = " + fileInfo.FormatName + "\n" +
                             "Format DLL Name = " + fileInfo.DllName + "\n" +
                             "Format Ext = " + fileInfo.ExtensionName + "\n" +
                             "Format Type = " + fileInfo.Type.ToString() + "\n");
          }
       }
       catch
       {
       }
    }
    
  5. Add the following code to button13 control’s click procedure:

    [Visual Basic]

    
    Private Sub button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button13.Click
       Try
          ' Set the RasterDocumentResultOptions format
          
          Dim resultOptions As RasterDocumentResultOptions = rasterDocument.SaveResultOptions
          Dim docOpts As RasterDocumentOptions = resultOptions.Document
          
          docOpts.PaperType = RasterDocumentPaperType.A4
          docOpts.PaperSizeMode = RasterDocumentSelector.Predefined
          resultOptions.Document = docOpts
    
          resultOptions.FormatLevel = RasterDocumentFormatLevel.Full
          resultOptions.Format = RasterDocumentFormatType.Word972000XP
          
          rasterDocument.SaveResultOptions = resultOptions
          
          ' Save the result of the recognition in a file
          rasterDocument.SaveResultsToFile("C:\OcrTest.doc")
          MessageBox.Show("The file has been successfully saved")
          
       Catch ex As Exception
          MessageBox.Show("Error: " + ex.Message + " in saving recognition result to a file")
       End Try
    End Sub
    
    [C#]
    
    private void button13_Click(object sender, System.EventArgs e)
    {
       try
       {
          // Set the RasterDocumentResultOptions format
          RasterDocumentResultOptions resultOptions = rasterDocument.SaveResultOptions;
          RasterDocumentOptions docOpts = resultOptions.Document;
          
          docOpts.PaperType = RasterDocumentPaperType.A4;
          docOpts.PaperSizeMode = RasterDocumentSelector.Predefined;
          resultOptions.Document = docOpts;
          resultOptions.FormatLevel = RasterDocumentFormatLevel.Full;
          resultOptions.Format = RasterDocumentFormatType.Word972000XP;
          
          rasterDocument.SaveResultOptions = resultOptions;
          
          // Save the result of the recognition in a file
          rasterDocument.SaveResultsToFile(@"C:\OcrTest.doc");
          MessageBox.Show("The file has been successfully saved");
       }
       catch(Exception ex)
       {
          MessageBox.Show("Error: " + ex.Message + " in saving recognition result to a file");
       }
    }
    
  6. Build, and Run the program to test it.
  7. Save this project to use for testing other code samples.