LEADTOOLS For .NET Class Library Send comments on this topic. | Back to Introduction - All Topics | Help Version 17.0.3.28
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. 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.Unlock call:

    [Visual Basic]

                // New code: Unlock the OCR PDF output support
                RasterSupport.Unlock(RasterSupportType.OcrPlusPdfLeadOutput, "Replace with your own key here");
                     
                
    

    [C#]

                // New code: Unlock the OCR PDF output support
                RasterSupport.Unlock(RasterSupportType.OcrPlusPdfLeadOutput, "Replace with your own key here");
                     
                
    

  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:

    Button Text button6 Recognize 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.