Take the following steps to create an ASP.NET AJAX-Enabled Web Application to OCR an image. The pre-requisite for this tutorial is that you have LEADTOOLS WCF OcrService hosted.
For more information on hosting the WCF services see: How to Host LEADTOOLS Services on IIS 7 or How to Host LEADTOOLS Services on IIS 5 and 6.
[Visual Basic]
Imports OcrServiceExample.OcrService
[C#]
using OcrServiceExample.OcrService;
[Visual Basic]
Dim loadData As FileBinaryData = New FileBinaryData()
loadData.FileName = "C:\Users\Public\Documents\LEADTOOLS Images\OCR1.tif"
Dim saveData As RawBinaryData = New RawBinaryData()
' Set the converstion options.
Dim convertOptions As DocumentConvertOptions = New DocumentConvertOptions()
convertOptions.Format = OcrDocumentFormatType.TextAnsi
convertOptions.Source = loadData
convertOptions.Destination = saveData
Dim request As RecognizeRequest = New RecognizeRequest()
request.ConvertOptions = convertOptions
Dim svc As OcrService.OcrServiceClient = New OcrService.OcrServiceClient()
Try
Dim response As RecognizeResponse = svc.Recognize(request)
saveData = CType(IIf(TypeOf response.Destination Is RawBinaryData, response.Destination, Nothing), RawBinaryData)
Finally
CType(svc, IDisposable).Dispose()
End Try
Label1.Text = "<pre>" & System.Text.Encoding.ASCII.GetString(save.Data) & "</pre>"
[C#]
FileBinaryData loadData = new FileBinaryData();
loadData.FileName = @"C:\Users\Public\Documents\LEADTOOLS Images\OCR1.tif";
RawBinaryData saveData = new RawBinaryData();
// Set the converstion options.
DocumentConvertOptions convertOptions = new DocumentConvertOptions();
convertOptions.Format = OcrDocumentFormatType.TextAnsi;
convertOptions.Source = loadData;
convertOptions.Destination = saveData;
RecognizeRequest request = new RecognizeRequest();
request.ConvertOptions = convertOptions;
using (OcrService.OcrServiceClient svc = new OcrService.OcrServiceClient())
{
RecognizeResponse response = svc.Recognize(request);
saveData = response.Destination as RawBinaryData;
}
Label1.Text = "<pre>" + System.Text.Encoding.ASCII.GetString(saveData.Data) + "</pre>";