LEADTOOLS OCR (Leadtools.Forms.Ocr assembly)
LEAD Technologies, Inc

OcrXmlOutputOptions Enumeration






Controls the format of the XML data obtained from IOcrDocument.SaveXml. .NET support WinRT support
Syntax
'Declaration
 
<FlagsAttribute()>
<SerializableAttribute()>
Public Enum OcrXmlOutputOptions 
   Inherits System.Enum
   Implements System.IComparableSystem.IConvertibleSystem.IFormattable 
'Usage
 
Dim instance As OcrXmlOutputOptions
Leadtools.Forms.Ocr.OcrXmlOutputOptions = function() { };
Leadtools.Forms.Ocr.OcrXmlOutputOptions.prototype = {
LeadtoolsMemberMarker(replace me) };
[FlagsAttribute()]
[SerializableAttribute()]
public enum class OcrXmlOutputOptions : public System.Enum, System.IComparableSystem.IConvertibleSystem.IFormattable  
Members
MemberDescription
CharacterAttributes

Only valid with Characters. Write the character attributes (font for example) in the result XML data.

Characters

Write the recognized character values instead of the word values in the result XML data

None

Default. Write the recognized word values in the result XML data.

Remarks

The various IOcrDocument.SaveXml methods accept a combination of one or more of the OcrXmlOutputOptions enumeration members to control the format of the output XML data.

The format of the result XML data is as follows:

             <?xml version="1.0" encoding="UTF-16" standalone="yes"?>
             <pages>
               <page>
                 <zone>
                   <paragraph>
                     <line>
                       <word>
                         <character/>
                         <character/>
                       </word>
                     </line>
                   </paragraph>
                 </zone>
               </page>
             </pages>
             

The pages element is repeated once per document and it has no value and no additional attributes.

The page element is repeated for every page in the document (IOcrDocument.Pages.Count). If this page has not been recognized or contains no zones, then the page element will not contain any child zone elements.

The page element has no value and contains the following additional attributes:

Attribute Value
horizontal_resolution Horizontal resolution of the page. The value is IOcrPage.DpiX.
vertical_resolution Vertical resolution of the page. The value is IOcrPage.DpiY.
width Width of the page in pixels. The value is IOcrPage.Width.
height Height of the page in pixels. The value is IOcrPage.Height.

The zone element is repeated for every zone in the current page (IOcrPage.Zones). The zone element has no value and contains the following additional attributes:

Attribute Value
type The zone type. Either "text" or "graphics". If the zone element is of type "text", then it will contain zero or more paragraph child elements. If the zone is of type "graphics", then it will not contain and other child elements.
left The zone left position in pixels. The value is OcrZone.Bounds.Left converted to pixels.
top The zone top position in pixels. The value is OcrZone.Bounds.Top converted to pixels.
right The zone right position in pixels. The value is OcrZone.Bounds.Right converted to pixels.
bottom The zone bottom position in pixels. The value is OcrZone.Bounds.Bottom converted to pixels.
subtype The zone type. The value is OcrZone.ZoneType.
recognition_module The zone recognition module. The value is OcrZone.RecognitionModule.
fill_method The fill method. The value is OcrZone.FillMethod.

The paragraph element is repeated for every text paragraph in the current zone and it has no attributes. If this zone has no recognition text, then the paragraph element will not contain any child line elements.

The paragraph element has no attributes and no value.

The line element is repeated for every line of text in the current paragraph. The line element has no value and contains the following additional attributes:

Attribute Value
left The line left position in pixels.
top The line top position in pixels.
right The line right position in pixels.
bottom The line bottom position in pixels. The value of left, top, right and bottom is calculated from the summation of all the boundaries of the words that make up this line.
base The position of the baseline of this line. The value is calculated from the summation of the baselines of all the words that make up this line.

The word element is repeated for every word of text in the current line. If OcrXmlOutputOptions.Characters was not specified in the generation options; then the word element will contain the value of the word as its value. Otherwise, the word element will contain no value.

The word element has the following attributes:

Attribute Value
left The word left position in pixels.
top The word top position in pixels.
right The word right position in pixels.
bottom The word bottom position in pixels. The value of left, top, right and bottom is calculated from the summation of all the boundaries of the characters that make up this word.
base The position of the baseline of this word. The value is calculated from the summation of the baselines of all the characters that make up this word.

The character element is repeated for every character in the following word only if OcrXmlOutputOptions.Characters was specified in the generation options. Otherwise, the word element will contain no child character elements. If OcrXmlOutputOptions.Characters was specified in the generation options; then the character element will contain the value of the character as its value. Otherwise, the character element will contain no value.

The character element contains the following additional attributes:

Attribute Value
left The character left position in pixels.
top The character top position in pixels.
right The character right position in pixels.
bottom The character bottom position in pixels. The value of left, top, right and bottom is calculated from OcrCharacter.Bounds.
base The position of the baseline of this character. The value is OcrCharacter.Base.
confidence The confidence of this character. The value is OcrCharacter.Confidence.
font_size The font size in points. The value is OcrCharacter.FontSize. Only available if OcrXmlOutputOptions.CharacterAttributes is specified.
proportional "yes" if the character font is proportional, "no"; otherwise. The value is calculated from OcrCharacter.FontStyle. Only available if OcrXmlOutputOptions.CharacterAttributes is specified.
serif "yes" if the character font is serif, "no"; otherwise. The value is calculated from OcrCharacter.FontStyle. Only available if OcrXmlOutputOptions.CharacterAttributes is specified.
bold "yes" if the character font is bold, "no"; otherwise. The value is calculated from OcrCharacter.FontStyle. Only available if OcrXmlOutputOptions.CharacterAttributes is specified.
italic "yes" if the character font is italic, "no"; otherwise. The value is calculated from OcrCharacter.FontStyle. Only available if OcrXmlOutputOptions.CharacterAttributes is specified.
underline "yes" if the character font is underline, "no"; otherwise. The value is calculated from OcrCharacter.FontStyle. Only available if OcrXmlOutputOptions.CharacterAttributes is specified.

The following is an example of the XML output when OcrXmlOutputOptions.None is specified:

             <?xml version="1.0" encoding="UTF-16" standalone="yes"?>
             <pages>
               <page horizontal_resolution="300" vertical_resolution="300" width="2544" height="3294">
                 <zone type="Text" left="371" top="370" right="831" bottom="420" subtype="Text" recognition_module="Auto" fill_method="Default">
                   <paragraph>
                     <line left="372" top="371" right="830" bottom="419" base="29">
                       <word left="372" top="371" right="554" bottom="409" base="30">License</word>
                       <word left="570" top="372" right="830" bottom="419" base="29">Agreement</word>
                     </line>
                   </paragraph>
                 </zone>
               </page>
             </pages>
             

Here is the same XML output when OcrXmlOutputOptions.Characters is specified:

             <?xml version="1.0" encoding="UTF-16" standalone="yes"?>
             <pages>
               <page horizontal_resolution="300" vertical_resolution="300" width="2544" height="3294">
                 <zone type="Text" left="371" top="370" right="831" bottom="420" subtype="Text" recognition_module="Auto" fill_method="Default">
                   <paragraph>
                     <line left="372" top="371" right="830" bottom="419" base="29">
                       <word left="372" top="371" right="554" bottom="409" base="30">
                         <character left="372" top="372" right="398" bottom="408" base="36" confidence="100">L</character>
                         <character left="402" top="371" right="409" bottom="408" base="37" confidence="100">i</character>
                         <character left="414" top="381" right="438" bottom="409" base="27" confidence="100">c</character>
                         <character left="442" top="381" right="468" bottom="409" base="27" confidence="100">e</character>
                         <character left="472" top="381" right="496" bottom="408" base="27" confidence="100">n</character>
                         <character left="501" top="381" right="525" bottom="408" base="27" confidence="100">s</character>
                         <character left="529" top="381" right="554" bottom="408" base="27" confidence="100">e</character>
                       </word>
                       <word left="570" top="372" right="830" bottom="419" base="29">
                         <character left="570" top="372" right="604" bottom="408" base="36" confidence="100">A</character>
                         <character left="607" top="381" right="633" bottom="419" base="27" confidence="100">g</character>
                         <character left="639" top="381" right="655" bottom="408" base="27" confidence="100">r</character>
                         <character left="657" top="381" right="682" bottom="408" base="27" confidence="100">e</character>
                         <character left="685" top="381" right="710" bottom="408" base="27" confidence="100">e</character>
                         <character left="715" top="381" right="753" bottom="408" base="27" confidence="100">m</character>
                         <character left="758" top="381" right="783" bottom="408" base="27" confidence="100">e</character>
                         <character left="788" top="381" right="812" bottom="408" base="27" confidence="100">n</character>
                         <character left="815" top="374" right="830" bottom="408" base="34" confidence="100">t</character>
                       </word>
                     </line>
                   </paragraph>
                 </zone>
               </page>
             </pages>
             

You can use the OcrXmlOutputOptions.CharacterAttributes option along with IOcrDocumentManager.GetFontNames to obtain the font family name of each character. When performing OCR, the engine cannot distinguish similar fonts such as Arial and Calibri, instead, the engine gets information on whether the character has serif and whether the font is proportional or fixed.

According to GetFontNames, the returned value is an array of fonts as follows:

Index Description
0 The font used with proportional serif characters
1 The font used with proportional sans-serif characters
2 The font used with monospaced serif characters
3 The font used with monospaced sans-serif characters
4 The font used with ICR (hand-written) characters
5 The font used with MICR (check font) characters

We are only interested in the first four values and with this information. As described above, using the CharacterAttributes option will add the following attributes to the element of each character in the XML: "proportional, serif, bold, italic". With this information and the font names obtained from GetFontNames, you can easily conclude the font family name. The following code snippet accomplishes this:

    
             private static void ShowFontNames(IOcrDocumentManager ocrDocumentManager, string xmlFileName)
             {
                // Get the Latin font names
                string[] fontNames = ocrDocumentManager.GetFontNames("en");
            
                // Note, you can also use a fixed array for most cases. The font names are not changed by the OCR engines
                // unless changed manually by the user:
                /*
                string[] fontNames =
                {
                   "Times New Roman",   // Proportional Serif
                   "Arial",             // Proportional Sans-Serif
                   "Courier New",       // Monospace Serif
                   "Arial"              // Monospace Sans-Serif
                };
                */
            
                // Read the XML file
                XPathDocument xmlDoc = new XPathDocument(xmlFileName);
                XPathNavigator nav = xmlDoc.CreateNavigator();
                XPathNodeIterator charactersIter = nav.Select(@"//character");
                while(charactersIter.MoveNext())
                {
                   XPathNavigator characterNav = charactersIter.Current;
            
                   // Read its attributes
                   bool isSerif;
                   bool isPropertional;
            
                   if(string.Compare(characterNav.GetAttribute("serif", characterNav.NamespaceURI), "yes", StringComparison.InvariantCultureIgnoreCase) == 0)
                      isSerif = true;
                   else
                      isSerif = false;
            
                   if(string.Compare(characterNav.GetAttribute("proportional", characterNav.NamespaceURI), "yes", StringComparison.InvariantCultureIgnoreCase) == 0)
                      isPropertional = true;
                   else
                      isPropertional = false;
            
                   // Now find the font based on this info
                   int index;
            
                   if(isPropertional && isSerif)
                      index = 0;
                   else if(isPropertional && !isSerif)
                      index = 1;
                   else if(!isPropertional && isSerif)
                      index = 2;
                   else
                      index = 3;
            
                   string fontName = fontNames[index];
                   Console.WriteLine("Character: {0} font: {1}", characterNav.Value, fontName);
                }
             }
             

  

Example
For an example, refer to IOcrDocument.SaveXml(string fileName, OcrXmlOutputOptions options) and IOcrDocument.SaveXml(OcrXmlOutputOptions options).
Inheritance Hierarchy

System.Object
   System.ValueType
      System.Enum
         Leadtools.Forms.Ocr.OcrXmlOutputOptions

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

Leadtools.Forms.Ocr Namespace
Leadtools.Forms.DocumentWriters.DocumentFormat
IOcrDocumentManager Interface
IOcrDocument Interface
IOcrDocument.Save
IOcrDocument.SaveXml
IOcrPage.Recognize
IOcrEngine Interface
OcrEngineManager Class
OcrEngineType Enumeration
Programming with the LEADTOOLS .NET OCR
Files to be Included with Your Application

 

 


Products | Support | Contact Us | Copyright Notices

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

OcrXmlOutputOptions requires an OCR module license and unlock key. For more information, refer to: Imaging Pro/Document/Medical Features