LEADTOOLS WCF OCR (Leadtools.Services.Forms.DataContracts assembly)
LEAD Technologies, Inc

DocumentFileInfo Class

Example 





Members 
The DocumentFileInfo class provides information for additional files generated by the Leadtools.Services.Forms.ServiceContracts.IOcrService.Recognize operation.
Object Model
DocumentFileInfo Class
Syntax
[DataContractAttribute(Namespace="http://Leadtools.Services.Forms.DataContracts/2009/01", Name="DocumentFileInfo")]
public class DocumentFileInfo 
'Declaration
 
<DataContractAttribute(Namespace="http://Leadtools.Services.Forms.DataContracts/2009/01", Name="DocumentFileInfo")>
Public Class DocumentFileInfo 
'Usage
 
Dim instance As DocumentFileInfo
public sealed class DocumentFileInfo 
function Leadtools.Services.Forms.DataContracts.DocumentFileInfo()
[DataContractAttribute(Namespace="http://Leadtools.Services.Forms.DataContracts/2009/01", Name="DocumentFileInfo")]
public ref class DocumentFileInfo 
Remarks
When DocumentConvertOptions.Format is set to OcrDocumentFormatType.Html32 or OcrDocumentFormatType.Html40, an additional directory will be generated. This directory will contain files necessary for the Html page:

For example if the file name is "Test.Html" then a "Test_files" will be created. “Test_files” will contain the images files. The references to these files, by default will be named “Leadtools_Rename_This” in the html file. All of these references need to be renamed to match the generated files.
Example
 
Private Sub Replace(ByVal docFileName As String, ByVal source As String, ByVal destination As String)
      ' Open a file for reading
      Dim streamReader As StreamReader
      streamReader = File.OpenText(docFileName)
      ' read the entire file into a string
      Dim contents As String = streamReader.ReadToEnd()
      streamReader.Close()

      Dim streamWriter As StreamWriter = File.CreateText(docFileName)

      streamWriter.Write(contents.Replace(source, destination))
      streamWriter.Close()
   End Sub


   Public Sub DocumentFilesExample()
      Dim client As OcrServiceClient = New OcrServiceClient()

      Dim sourceBinaryData As RawBinaryData = New RawBinaryData()
      sourceBinaryData.Data = File.ReadAllBytes(Path.Combine(LEAD_VARS.ImagesDir, "clean.tif"))

      ' set the document convertion options
      Dim convertOptions As DocumentConvertOptions = New DocumentConvertOptions()

      convertOptions.Source = sourceBinaryData
      convertOptions.Destination = Nothing
      convertOptions.Format = OcrDocumentFormatType.Html
      convertOptions.FirstPageNumber = 1
      convertOptions.LastPageNumber = 1
      Dim files As DocumentFiles = Nothing

      Dim request As RecognizeRequest = New RecognizeRequest()
      request.ConvertOptions = convertOptions

      Dim response As RecognizeResponse = client.Recognize(request)

      If Not response.Destination Is Nothing Then
         Dim outFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "clean.html")

         If TypeOf response.Destination Is RawBinaryData Then
            File.WriteAllBytes(outFileName, (TryCast(response.Destination, RawBinaryData)).Data)
            If Not response.Files Is Nothing Then
               Replace(outFileName, "Leadtools_Rename_This", Path.GetFileNameWithoutExtension(outFileName))
               Dim directory As String = Path.GetDirectoryName(outFileName) & "\" & Path.GetFileNameWithoutExtension(outFileName) & "_Dir"
               System.IO.Directory.CreateDirectory(directory)
               For Each info As DocumentFileInfo In files
                  File.WriteAllBytes(directory & "\" & info.FileName, info.FileData.Data)
               Next info
            End If
         End If
      End If

      client.Close()
   End Sub

Public NotInheritable Class LEAD_VARS
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
private void Replace(string docFileName, string source, string destination)
   {
      // Open a file for reading
      StreamReader streamReader;
      streamReader = File.OpenText(docFileName);
      // read the entire file into a string
      string contents = streamReader.ReadToEnd();
      streamReader.Close();

      StreamWriter streamWriter = File.CreateText(docFileName);

      streamWriter.Write(contents.Replace(source, destination));
      streamWriter.Close();
   }


   public void DocumentFilesExample()
   {
      OcrServiceClient client = new OcrServiceClient();

      RawBinaryData sourceBinaryData = new RawBinaryData();
      sourceBinaryData.Data = File.ReadAllBytes(Path.Combine(LEAD_VARS.ImagesDir,"clean.tif"));

      // set the document convertion options
      DocumentConvertOptions convertOptions = new DocumentConvertOptions();

      convertOptions.Source = sourceBinaryData;
      convertOptions.Destination = null;
      convertOptions.Format  = OcrDocumentFormatType.Html;
      convertOptions.FirstPageNumber = 1;
      convertOptions.LastPageNumber = 1;
      DocumentFiles files = null;

      RecognizeRequest request = new RecognizeRequest();
      request.ConvertOptions = convertOptions;

      RecognizeResponse response = client.Recognize(request);

      if (response.Destination != null)
      {
         string outFileName = Path.Combine(LEAD_VARS.ImagesDir,"clean.html");

         if (response.Destination is RawBinaryData)
         {
            File.WriteAllBytes(outFileName, (response.Destination as RawBinaryData).Data);
            if (response.Files != null)
            {
               Replace(outFileName, "Leadtools_Rename_This", Path.GetFileNameWithoutExtension(outFileName));
               string directory = Path.GetDirectoryName(outFileName) + "\\" + Path.GetFileNameWithoutExtension(outFileName) + "_Dir";
               Directory.CreateDirectory(directory);
               foreach (DocumentFileInfo info in files)
               {
                  File.WriteAllBytes(directory + "\\" + info.FileName, info.FileData.Data);
               }
            }
         }
      }

      client.Close();
   }

static class LEAD_VARS
{
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

DocumentFileInfo Members
Leadtools.Services.Forms.DataContracts Namespace

 

 


Products | Support | Contact Us | Copyright Notices

© 2006-2012 All Rights Reserved. LEAD Technologies, Inc.

Applications developed with LEADTOOLS WCF components require runtime licenses. Server licensing is required for applications on a server. For more information, refer to: Imaging Pro/Document/Medical