Save(string,OcrWriteXmlOptions) Method (original) (raw)
Summary
Saves the OCR engine current settings to a disk file.
Syntax
Parameters
fileName
The name of the file containing the settings to read.
xmlOptions
XML options to use.
Example
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Ocr;
using Leadtools.Document.Writer;
public void LoadSettingsExample1()
{
string settingsFileName = Path.Combine(LEAD_VARS.ImagesDir, "PlusSettings.xml");
string userDictionaryFileName = Path.Combine(LEAD_VARS.ImagesDir, "MyDictionary.ud");
// Create an instance of the engine
using (IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.LEAD))
{
// Start the engine using default parameters
ocrEngine.Startup(null, null, null, LEAD_VARS.OcrLEADRuntimeDir);
IOcrSettingManager settingManager = ocrEngine.SettingManager;
// Enable English and German character sets
ocrEngine.LanguageManager.EnableLanguages(new string[] { "en", "de" });
// Set the spell checking options
ocrEngine.SpellCheckManager.SpellCheckEngine = OcrSpellCheckEngine.Native;
ocrEngine.SpellCheckManager.SpellLanguage = "en";
// Change some settings
settingManager.SetValue("SaveDocument.FormatLevel", "Part");
settingManager.SetBooleanValue("SaveDocument.Document.TextInBoxes", false);
settingManager.SetIntegerValue("SaveDocument.Document.Margin.Left", 2400);
settingManager.SetStringValue("SaveDocument.Character.ProportionalSansSerifFontName", "MyFont");
settingManager.SetStringValue("SaveDocument.Mark.BeforeMissingCharacterSeparator", "MyMark");
settingManager.SetValue("SaveDocument.Mark.BeginOfLineSeparator", null);
// Change an enum using an integer
settingManager.SetEnumValue("SaveDocument.Mark.SuspectedCharacterColor", 7);
// Change an enum using strings
settingManager.SetEnumValue("SaveDocument.Mark.RejectionCharacterColor", "Blue, Green, Red");
// Save the settings
settingManager.Save(settingsFileName);
// Note: calling Dispose will also automatically shutdown the engine if it has been started
ocrEngine.Shutdown();
}
// Now create another instance of the engine, load the settings and make sure they are the same
using (IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.LEAD))
{
// Start the engine using default parameters
ocrEngine.Startup(null, null, null, LEAD_VARS.OcrLEADRuntimeDir);
IOcrSettingManager settingManager = ocrEngine.SettingManager;
// Load the settings
settingManager.Load(settingsFileName);
// Check the character set
string[] languages = ocrEngine.LanguageManager.GetEnabledLanguages();
Debug.Assert(languages[0] == "en" && languages[1] == "de");
// Check the spell checking options
Debug.Assert(ocrEngine.SpellCheckManager.SpellCheckEngine == OcrSpellCheckEngine.Native);
Debug.Assert(ocrEngine.SpellCheckManager.SpellLanguage == "en");
// Check the settings
Debug.Assert(settingManager.GetValue("SaveDocument.FormatLevel") == "Part");
Debug.Assert(settingManager.GetBooleanValue("SaveDocument.Document.TextInBoxes") == false);
Debug.Assert(settingManager.GetIntegerValue("SaveDocument.Document.Margin.Left") == 2400);
Debug.Assert(settingManager.GetStringValue("SaveDocument.Character.ProportionalSansSerifFontName") == "MyFont");
Debug.Assert(settingManager.GetStringValue("SaveDocument.Mark.BeforeMissingCharacterSeparator") == "MyMark");
Debug.Assert(settingManager.GetValue("SaveDocument.Mark.BeginOfLineSeparator") == null);
Debug.Assert(settingManager.GetEnumValue("SaveDocument.Mark.SuspectedCharacterColor") == 7);
Debug.Assert(settingManager.GetEnumValueAsString("SaveDocument.Mark.RejectionCharacterColor") == "Blue, Green, Red");
// Note: calling Dispose will also automatically shutdown the engine if it has been started
ocrEngine.Shutdown();
}
}
static class LEAD_VARS
{
public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images";
public const string OcrLEADRuntimeDir = @"C:\LEADTOOLS22\Bin\Common\OcrLEADRuntime";
}