Recognize(string,string,string,OcrDocumentFormatType) Method
Summary
Converts an image to a document in the specified document format.
Syntax
[WebGetAttribute()]
[FaultContractAttribute(System.Type)]
[OperationContractAttribute(Name="RecognizeImage",
Action="RecognizeImage",
AsyncPattern=false,
IsOneWay=false,
IsInitiating=true,
IsTerminating=false)]
public Stream Recognize(
string uri,
string username,
string password,
OcrDocumentFormatType format
)
<OperationContractAttribute(Name="RecognizeImage", Action="RecognizeImage")>
<WebGetAttribute()>
<FaultContractAttribute(DetailType=Leadtools.Services.Raster.FaultContracts.RasterFault,
Action="",
Name="",
Namespace="",
ProtectionLevel=ProtectionLevel.None,
HasProtectionLevel=False)>
Overloads Function Recognize( _
ByVal uri As String, _
ByVal username As String, _
ByVal password As String, _
ByVal format As Leadtools.Services.Forms.Datacontracts.OcrDocumentFormatType _
) As Stream
Parameters
username
The username who has privileges on the specified URI. Must be passed as (domain/username).
password
The password for the specified user.
Return Value
A stream that contains the document data.
Example
This example will convert a TIF file in a sharepoint to text and save it to disk.
using Leadtools.Services;
using Leadtools.Services.Forms.ServiceContracts;
using Leadtools.Services.Forms.ServiceImplementations;
public void RecognizeImageExample()
{
byte[] buffer = new byte[1024 * 64];
int totalBytesRead = 0;
MemoryStream memoryStream = new MemoryStream();
OcrServiceClient client = new OcrServiceClient();
Stream stream = client.RecognizeImage(@"http://sp2007ep/Ocr/Shared%20Documents/OCR.TIF", "username", "password", OcrDocumentFormatType.TextAnsi);
int bytesRead;
while ((bytesRead = stream.Read(buffer, 0, buffer.Length)) > 0)
{
totalBytesRead += bytesRead;
memoryStream.Write(buffer, 0, bytesRead);
}
File.WriteAllBytes(Path.Combine(LEAD_VARS.ImagesDir, "ocr.txt"), memoryStream.ToArray());
client.Close();
}
static class LEAD_VARS
{
public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
Imports Leadtools.Services
Imports Leadtools.Services.Forms.ServiceContracts
Imports Leadtools.Services.Forms.ServiceImplementations
Public Sub RecognizeImageExample()
Dim buffer As Byte() = New Byte(1024 * 64 - 1) {}
Dim totalBytesRead As Integer = 0
Dim memoryStream As MemoryStream = New MemoryStream()
Dim client As OcrServiceClient = New OcrServiceClient()
Dim stream As Stream = client.RecognizeImage("http://sp2007ep/Ocr/Shared%20Documents/OCR.TIF", "username", "password", OcrDocumentFormatType.TextAnsi)
Dim bytesRead As Integer
'TODO: INSTANT VB TODO TASK: Assignments within expressions are not supported in VB.NET
'ORIGINAL LINE: while ((bytesRead = stream.Read(buffer, 0, buffer.Length)) > 0)
Do While (bytesRead = stream.Read(buffer, 0, buffer.Length)) > 0
totalBytesRead += bytesRead
memoryStream.Write(buffer, 0, bytesRead)
Loop
File.WriteAllBytes(Path.Combine(LEAD_VARS.ImagesDir, "ocr.txt"), memoryStream.ToArray())
client.Close()
End Sub
Public NotInheritable Class LEAD_VARS
Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class