←Select platform

OcrWriteXmlOptions Class

Summary

Options to use when saving XML data.

Syntax

C#
VB
Java
Objective-C
WinRT C#
C++
[SerializableAttribute()] 
public class OcrWriteXmlOptions 
<SerializableAttribute()> 
Public Class OcrWriteXmlOptions  
public sealed class OcrWriteXmlOptions  
@interface LTOcrWriteXmlOptions : NSObject 
public class OcrWriteXmlOptions 
function Leadtools.Forms.Ocr.OcrWriteXmlOptions() 
[SerializableAttribute()] 
public ref class OcrWriteXmlOptions  

Remarks

OcrWriteXmlOptions allows to control how XML data is written. It has the following members:

Member Description
Encoding

Set the encoding of the XML data. UTF8 or UTF16

Formatted

Format the document for human reading

Indent

The string to use for indentation when saving the XML data.

Example

C#
VB
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Forms.Ocr; 
using Leadtools.Forms; 
using Leadtools.Forms.DocumentWriters; 
using Leadtools.WinForms; 
using Leadtools.Drawing; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Color; 
 
private static void OcrWriteXmlOptionsExample() 
{ 
   var imageFileName = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.tif"); 
   var formattedFileName = Path.Combine(LEAD_VARS.ImagesDir, "formatted.xml"); 
   var nonFormattedFileName = Path.Combine(LEAD_VARS.ImagesDir, "non_formatted.xml"); 
 
   using (IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Advantage, false)) 
   { 
      ocrEngine.Startup(null, null, null, LEAD_VARS.OcrAdvantageRuntimeDir); 
 
      // Load an image 
      var rasterImage = ocrEngine.RasterCodecsInstance.Load(imageFileName, 1); 
 
      // Create an OCR page from it 
      using (var ocrPage = ocrEngine.CreatePage(rasterImage, OcrImageSharingMode.AutoDispose)) 
      { 
         // Recognize 
         ocrPage.Recognize(null); 
 
         // Save the result as XML 
 
         // First, non-fomrtted 
         var writeXmlOptions = new OcrWriteXmlOptions(); 
         writeXmlOptions.Formatted = false; 
         ocrPage.SaveXml(formattedFileName, 1, writeXmlOptions, OcrXmlOutputOptions.None); 
 
         // Next, formatted with 4 spaces idententation 
         writeXmlOptions.Formatted = true; 
         writeXmlOptions.Indent = "  "; 
         ocrPage.SaveXml(nonFormattedFileName, 1, writeXmlOptions, OcrXmlOutputOptions.None); 
      } 
   } 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images"; 
   public const string OcrAdvantageRuntimeDir = @"C:\LEADTOOLS 19\Bin\Common\OcrAdvantageRuntime"; 
} 
Imports Leadtools 
Imports Leadtools.Codecs 
Imports Leadtools.Forms.Ocr 
Imports Leadtools.Forms 
Imports Leadtools.Forms.DocumentWriters 
Imports Leadtools.WinForms 
Imports Leadtools.Drawing 
Imports Leadtools.ImageProcessing 
Imports Leadtools.ImageProcessing.Color 
 
Private Shared Sub OcrWriteXmlOptionsExample() 
   Dim imageFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.tif") 
   Dim formattedFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "formatted.xml") 
   Dim nonFormattedFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "non_formatted.xml") 
 
   Using ocrEngine As IOcrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Advantage, False) 
      ocrEngine.Startup(Nothing, Nothing, Nothing, LEAD_VARS.OcrAdvantageRuntimeDir) 
 
      ' Load an image 
      Dim rasterImage As RasterImage = ocrEngine.RasterCodecsInstance.Load(imageFileName, 1) 
 
      ' Create an OCR page from it 
      Using ocrPage As IOcrPage = ocrEngine.CreatePage(rasterImage, OcrImageSharingMode.AutoDispose) 
         ' Recognize 
         ocrPage.Recognize(Nothing) 
 
         ' Save the result as XML 
 
         ' First, non-fomrtted 
         Dim writeXmlOptions As New OcrWriteXmlOptions() 
         writeXmlOptions.Formatted = False 
         ocrPage.SaveXml(formattedFileName, 1, writeXmlOptions, OcrXmlOutputOptions.None) 
 
         ' Next, formatted with 4 spaces idententation 
         writeXmlOptions.Formatted = True 
         writeXmlOptions.Indent = "  " 
         ocrPage.SaveXml(nonFormattedFileName, 1, writeXmlOptions, OcrXmlOutputOptions.None) 
      End Using 
   End Using 
End Sub 
 
Public NotInheritable Class LEAD_VARS 
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images" 
   Public Const OcrAdvantageRuntimeDir As String = "C:\LEADTOOLS 19\Bin\Common\OcrAdvantageRuntime" 
End Class 

Requirements

Target Platforms

Help Version 19.0.2017.10.27
Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Forms.Ocr Assembly