Take the following steps to add code to the existing project that
demonstrates how to work with pages in an OCR document:
Start with the program you created in Working with Pages. Drag and drop three buttons in Form1. Leave all the buttons names as the default "button7, button8, button9 ", then change the following properties of button7: Property Value Text Find Zones Change the following properties of button8: Property Value Text Zones Count Change the following properties of button9: Property Value Text Verify Zone Switch to Form1 code view (Right-click Form1 in the solution explorer then select View Code ) and add the following code to the button7 control’s click procedure: [Visual Basic]
[C#]Private Sub button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button7.Click Try ' Find all the zones of the first page of RasterDocument object rasterDocument.EnableZoneForceSingleColumn = True rasterDocument.ShowZoneGridlines = True rasterDocument.FindZones(0, Rectangle.Empty) MessageBox.Show("Automatic zones method finds all available zones into the specified pages successfully") Catch ex As Exception ' Error MessageBox.Show("Error: " + ex.Message + " in finding available zone in the specified page") End Try End Sub
private void button7_Click(object sender, System.EventArgs e) { try { // Find all the zones of the first page of RasterDocument object rasterDocument.EnableZoneForceSingleColumn = true; rasterDocument.ShowZoneGridlines = true; rasterDocument.FindZones(0, Rectangle.Empty); MessageBox.Show("Automatic zones method finds all available zones into the specified pages successfully"); } catch(Exception ex) { //Error MessageBox.Show("Error: " + ex.Message + " in finding available zone in the specified page"); } }
Add the following code to the button8 control’s click procedure: [Visual Basic]
[C#]Private Sub button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button8.Click ' Print the number of zones in the first page MessageBox.Show("Total zones count = " & rasterDocument.GetZoneCount(0)) End Sub
private void button8_Click(object sender, System.EventArgs e) { // Print the number of zones in the first page MessageBox.Show("Total zones count = " + rasterDocument.GetZoneCount(0)); }
Add the following code to the button9 control’s click procedure: [Visual Basic]
[C#]Private Sub button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button9.Click Dim zonesCount As Integer Dim i As Integer zonesCount = rasterDocument.GetZoneCount(0) For i = 0 To zonesCount - 1 ' Get The zones information of the first page of RasterDocument object rasterDocumentZoneData = rasterDocument.GetZone(0, i) rasterDocumentZoneData.Flags = (rasterDocumentZoneData.Flags And (Not RasterDocumentZoneFlags.DoNotUseVerificationEvent)) Try ' Update the zones information of the first page of RasterDocument object rasterDocument.UpdateZone(0, i, rasterDocumentZoneData) Catch ex As Exception MessageBox.Show("Error: " + ex.Message + " in updating zone # " + i.ToString()) End Try Next i End Sub
private void button9_Click(object sender, System.EventArgs e) { int zonesCount; int i; zonesCount = rasterDocument.GetZoneCount(0); for (i = 0; i < zonesCount; i++) { // Get The zones information of the first page of RasterDocument object rasterDocumentZoneData = rasterDocument.GetZone(0, i); rasterDocumentZoneData.Flags = (rasterDocumentZoneData.Flags & (~RasterDocumentZoneFlags.DoNotUseVerificationEvent)); try { // Update the zones information of the first page of RasterDocument object rasterDocument.UpdateZone(0, i, rasterDocumentZoneData); } catch(Exception ex) { MessageBox.Show("Error: " + ex.Message + " in updating zone # " + i.ToString()); } } }
Build, and Run the program to test it. Save this project to use for testing other code samples.