Take the following steps to start a project and to add some code
that demonstrates how to draw pages and zones:
Start with the program you created in Working with Zones . Drag and drop two buttons in Form1. Leave all the buttons names as the default "button10, button11 ...", then change the following properties of button10: Property Value Text Recognize Change the following properties of button11: Property Value Text Gets Status 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]
[C#]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
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"); } }
Add the following code to button11 control’s click procedure: [Visual Basic]
[C#]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
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); }
Add the following code to Form1 Class [Visual Basic]
[C#]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
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; }
Build and Run the project to test it. Save this project to be used for testing other code samples.