Products | Support | Email a link to this topic. | Send comments on this topic. | Back to Introduction | Help Version 19.0.6.21
|
Button | Text |
---|---|
button1 | Startup |
button2 | Add Page |
button3 | Remove Pages |
button4 | Flip Page |
button5 | Shutdown |
using
or Imports
section if there are any:
[C#]
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Forms;
using Leadtools.Forms.DocumentWriters;
using Leadtools.Forms.Ocr;
using Leadtools.ImageProcessing;
[Visual Basic]
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.Forms
Imports Leadtools.Forms.DocumentWriters
Imports Leadtools.Forms.Ocr
Imports Leadtools.ImageProcessing
[C#]
private IOcrEngine _ocrEngine;
private IOcrDocument _ocrDocument;
[Visual Basic]
Private _ocrEngine As IOcrEngine
Private _ocrDocument As IOcrDocument
Click
handler:
[C#]
private void button1_Click(object sender, EventArgs e)
{
// Initialize the OCR engine
_ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Advantage, false);
// Start it up
_ocrEngine.Startup(null, null, null, @"C:\LEADTOOLS 19\Bin\Common\OcrAdvantageRuntime");
// Create the document
_ocrDocument = _ocrEngine.DocumentManager.CreateDocument();
MessageBox.Show("OCR engine has been started successfully and document created");
}
[Visual Basic]
Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
' Initialize the OCR engine
_ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Advantage, False)
' Start it up
_ocrEngine.Startup(Nothing, Nothing, Nothing, "C:\LEADTOOLS 19\Bin\Common\OcrAdvantageRuntime")
' Create the document
_ocrDocument = _ocrEngine.DocumentManager.CreateDocument()
MessageBox.Show("OCR engine has been started successfully and document created")
End Sub
Click
handler:
[C#]
private void button2_Click(object sender, EventArgs e)
{
// Browse to an existing document file on disk, for example @"C:\Users\Public\Documents\LEADTOOLS Images\Ocr1.tif";
string fileName = null;
using (OpenFileDialog dlg = new OpenFileDialog())
{
if (dlg.ShowDialog(this) == DialogResult.OK)
fileName = dlg.FileName;
}
if (fileName == null)
return;
// Add the first page from the file to the OCR document
IOcrPage page = _ocrDocument.Pages.AddPage(fileName, null);
int pageCount = _ocrDocument.Pages.Count;
// Show some information about this page
string message = string.Format(
"Total pages is {0}\nLast page added size = {1} by {2}\nResolution = {3} by {4}\nBits per pixel = {5}",
pageCount,
page.Width, page.Height,
page.DpiX, page.DpiY,
page.BitsPerPixel);
MessageBox.Show(message);
}
[Visual Basic]
Private Sub button2_Click(sender As Object, e As EventArgs)
' Browse to an existing document file on disk, for example @"C:\Users\Public\Documents\LEADTOOLS Images\Ocr1.tif";
Dim fileName As String = Nothing
Using dlg As New OpenFileDialog()
If dlg.ShowDialog(Me) = DialogResult.OK Then
fileName = dlg.FileName
End If
End Using
If IsNothing(fileName) Then Return
' Add the first page from the file to the OCR document
Dim page As IOcrPage = _ocrDocument.Pages.AddPage(fileName, Nothing)
Dim pageCount As Integer = _ocrDocument.Pages.Count
' Show some information about this page
Dim message As String = String.Format( _
"Total pages is {0}\nLast page added size = {1} by {2}\nResolution = {3} by {4}\nBits per pixel = {5}", _
pageCount, _
page.Width, page.Height, _
page.DpiX, page.DpiY, _
page.BitsPerPixel)
MessageBox.Show(message)
End Sub
Click
handler:
[C#]
private void button3_Click(object sender, EventArgs e)
{
// Remove all added pages from the OCR document
_ocrDocument.Pages.Clear();
MessageBox.Show("All the pages has been removed");
}
[Visual Basic]
Private Sub button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button3.Click
' Remove all added pages from the OCR document
_ocrDocument.Pages.Clear()
MessageBox.Show("All the pages has been removed")
End Sub
Click
handler:
[C#]
private void button4_Click(object sender, EventArgs e)
{
// Get the last page added to the OCR document
if (_ocrDocument.Pages.Count < 1)
return;
IOcrPage page = _ocrDocument.Pages[_ocrDocument.Pages.Count - 1];
// Get a RasterImage that represents this page
using (RasterImage image = page.GetRasterImage())
{
// Flip this image vertically
FlipCommand cmd = new FlipCommand(false);
cmd.Run(image);
// The RasterImage is a copy of the page, so update it
page.SetRasterImage(image);
MessageBox.Show("Last page has been flipped");
}
}
[Visual Basic]
Private Sub button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button4.Click
' Get the last page added to the OCR document
If (_ocrDocument.Pages.Count < 1) Then
Return
End If
Dim page As IOcrPage = _ocrDocument.Pages(_ocrDocument.Pages.Count - 1)
' Get a RasterImage that represents this page
Using image As RasterImage = page.GetRasterImage()
' Flip this image vertically
Dim cmd As New FlipCommand(False)
cmd.Run(image)
' The RasterImage is a copy of the page, so update it
page.SetRasterImage(image)
MessageBox.Show("Last page has been flipped")
End Using
End Sub
Click
handler:
[C#]
private void button5_Click(object sender, EventArgs e)
{
// Destroy the document
_ocrDocument.Dispose();
// Destroy the engine (will also shut it down)
_ocrEngine.Dispose();
MessageBox.Show("OCR engine and document has been destroyed")
}
[Visual Basic]
Private Sub button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button5.Click
' Destroy the document
_ocrDocument.Dispose()
' Destroy the engine (will also shut it down)
_ocrEngine.Dispose()
MessageBox.Show("OCR engine and document has been destroyed")
End Sub
OCR Tutorial - Recognizing Pages
OCR Tutorial - Adding and Painting Zones
OCR Tutorial - Working with Recognition Results
OCR Tutorial - Scanning to Searchable PDF
Introduction
Getting Started (Guide to Example Programs)
LEADTOOLS OCR .NET Assemblies
Programming with LEADTOOLS .NET OCR
An Overview of OCR Recognition Modules
Creating an OCR Engine Instance
Starting and Shutting Down the OCR Engine
Multi-Threading with LEADTOOLS OCR
OCR Spell Language Dictionaries
Working with OCR Languages
Working with OCR Pages
Working with OCR Zones
Recognizing OCR Pages
OCR Confidence Reporting
Using OMR in LEADTOOLS .NET OCR
OCR Languages and Spell Checking
OCR Engine-Specific Settings