OCR Tutorial - Recognizing Pages

Show in webframe

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. This tutorial will save the final result as a PDF file. Therefore, we need to unlock the PDF support first. Modify Form1 constructor to add the following lines just below the first RasterSupport.SetLicense call:

    [Visual Basic]

    
                ' New code: Unlock the OCR PDF output support
                Dim MY_LICENSE_FILE As String = "d:\temp\TestLic.lic"
                Dim MY_DEVELOPER_KEY As String = "xyz123abc"
                RasterSupport.SetLicense(MY_LICENSE_FILE, MY_DEVELOPER_KEY);
                     
                
    

    [C#]

    
                // New code: Unlock the OCR PDF output support
                string MY_LICENSE_FILE = "d:\\temp\\TestLic.lic";
                string MY_DEVELOPER_KEY = "xyz123abc";
                RasterSupport.SetLicense(MY_LICENSE_FILE, MY_DEVELOPER_KEY);
                     
                
    
  3. 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

  4. Add the following code for the button6 (Recognize and Save) control's Clickhandler:

    [Visual Basic]

    
                Private Sub button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button6.Click
                   ' 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 perfomrs
                   ' auto-zoning for us automatically
                   _ocrDocument.Pages.Recognize(Nothing)
                   ' Save the result as a PDF file
                   Dim pdfFileName As String = "C:\Users\Public\Documents\LEADTOOLS Images\Ocr1.pdf"
                   _ocrDocument.Save(pdfFileName, DocumentFormat.Pdf, Nothing)
                   ' Show the PDF file we just saved
                   System.Diagnostics.Process.Start(pdfFileName)
                End Sub
                     
                
    

    [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 perfomrs
                   // auto-zoning for us automatically
                   _ocrDocument.Pages.Recognize(null);
                   // Save the result as a PDF file
                   string pdfFileName = @"C:\Users\Public\Documents\LEADTOOLS Images\Ocr1.pdf";
                   _ocrDocument.Save(pdfFileName, DocumentFormat.Pdf, null);
                   // Show the PDF file we just saved
                   System.Diagnostics.Process.Start(pdfFileName);
                }
                     
                
    
  5. 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".

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


Products | Support | Contact Us | Copyright Notices
© 2006-2014 All Rights Reserved. LEAD Technologies, Inc.