In This Topic ▼

OCR Tutorial - Recognizing Pages

Take the following steps to start a project and to add some code that demonstrates how to recognize zones:

  1. Start with the program you created in OCR Tutorial - Working with Pages

  2. Drag and drop a button in Form1. Leave the button name as the default "button6", then change the Text property of the button to the following:

    ButtonTextbutton6Recognize and Save

  3. Add the following code for the button6 (Recognize and Save) Click handler:

    C#
          private void button6_Click(object sender, EventArgs e) 
          { 
             // Recognize all the pages we have 
             // Note, we do not have to call AutoZone, the engine 
             // will check if the page(s) have not been zoned and perform 
             // auto-zoning for us automatically 
             _ocrDocument.Pages.Recognize(null); 
                     
             // Prompt the user for a PDF file 
             string fileName = null; 
             using (SaveFileDialog dlg = new SaveFileDialog()) 
             { 
                dlg.Filter = "PDF files|*.pdf|All files|*.*"; 
                dlg.DefaultExt = "pdf"; 
                if (dlg.ShowDialog(this) == DialogResult.OK) 
                   fileName = dlg.FileName; 
             } 
                     
             if (fileName == null) 
                return; 
                     
             // Save the result as a PDF file 
             _ocrDocument.Save(fileName, DocumentFormat.Pdf, null); 
             // Show the PDF file we just saved 
             System.Diagnostics.Process.Start(fileName); 
          } 
    VB
          Private Sub button6_Click(sender As Object, e As EventArgs) 
             ' Recognize all the pages we have 
             ' Note, we do not have to call AutoZone, the engine 
             ' will check if the page(s) have not been zoned and perform 
             ' auto-zoning for us automatically 
             _ocrDocument.Pages.Recognize(Nothing) 
                     
             ' Prompt the user for a PDF file 
             Dim fileName As String = Nothing 
             Using dlg As New SaveFileDialog() 
                dlg.Filter = "PDF files|*.pdf|All files|*.*" 
                dlg.DefaultExt = "pdf" 
                If (dlg.ShowDialog(Me) = DialogResult.OK) Then 
                   fileName = dlg.FileName 
                End If 
             End Using 
                     
             If IsNothing(fileName) Then Return 
                     
             ' Save the result as a PDF file 
             _ocrDocument.Save(fileName, DocumentFormat.Pdf, Nothing) 
             ' Show the PDF file we just saved 
             System.Diagnostics.Process.Start(fileName) 
          End Sub 

  4. Build, and Run the program to test it. You can click the buttons in the following order to create the PDF file "Startup", "Add Page", "Save and Recognize", "Shutdown".

  5. Save this project to use for testing other code samples.

Help Version 20.0.2020.4.3
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2020 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Imaging, Medical, and Document