[SerializableAttribute()]
public enum OcrDocumentFontType
Value | Member | Description |
---|---|---|
0 | ProportionalSerif | The font used with proportional serif characters |
1 | ProportionalSansSerif | The font used with proportional sans-serif characters |
2 | FixedSerif | The font used with monospaced serif characters |
3 | FixedSansSerif | The font used with monospaced sans-serif characters |
4 | MICR | The font used with MICR (check font) characters |
OcrDocumentFontType is used with IOcrDocumentManager.GetFontName and IOcrDocumentManager.SetFontName to get/set the fonts used in the final recognized document (PDF, DOC, HTML, etc)..
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Ocr;
using Leadtools.Forms.Common;
using Leadtools.Document.Writer;
using Leadtools.WinForms;
public void DocumentFontsTest()
{
using (RasterCodecs codecs = new RasterCodecs())
{
using (IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.LEAD))
{
ocrEngine.Startup(codecs, null, null, LEAD_VARS.OcrLEADRuntimeDir);
IOcrDocumentManager ocrDocumentManager = ocrEngine.DocumentManager;
using (IOcrDocument ocrDocument = ocrEngine.DocumentManager.CreateDocument())
{
// Add a page to OCR
IOcrPage ocrPage = ocrDocument.Pages.AddPage(Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.tif"), null);
ocrPage.AutoZone(null);
ocrPage.Recognize(null);
// Show the current fonts used to save default documents
Console.WriteLine("Saving use the following fonts:");
ShowFonts(ocrDocumentManager);
ocrDocument.Save(Path.Combine(LEAD_VARS.ImagesDir, "Ocr1_DefaultFonts.pdf"), DocumentFormat.Pdf, null);
// Now change the fonts to something else
string[] newFonts = ocrDocumentManager.GetFontNames(null);
// Use Cambira for Proportional Serif font - instead of Times New Roman
newFonts[0] = "Cambria";
// Use Calibri for Proportional Sans-serif font - instead of Arial
newFonts[1] = "Calibri";
// Use Lucida Console for Monospace fonts (both Serif and Sans-serif)
newFonts[2] = "Lucida Console";
newFonts[3] = "Lucida Console";
// Leave the ICR and MICR fonts the same
ocrDocumentManager.SetFontNames(null, newFonts);
// Show the new fonts used to save default documents
Console.WriteLine("Saving use the following fonts:");
ShowFonts(ocrDocumentManager);
ocrDocument.Save(Path.Combine(LEAD_VARS.ImagesDir, "Ocr1_CustomFonts.pdf"), DocumentFormat.Pdf, null);
}
}
}
}
private static void ShowFonts(IOcrDocumentManager ocrDocumentManager)
{
// Get the default fonts
// The default fonts will be used for all Latin languages
string[] fonts = ocrDocumentManager.GetFontNames(null);
// This should return an array of 6 items, as follows:
Console.WriteLine("Proportional Serif font: " + fonts[0]);
Console.WriteLine("Proportional Sans-serif font: " + fonts[1]);
Console.WriteLine("Monospace Serif font: " + fonts[2]);
Console.WriteLine("Monospace Sans-serif font: " + fonts[3]);
Console.WriteLine("ICR (hand-written) font: " + fonts[4]);
Console.WriteLine("MICR (Check) font: " + fonts[5]);
}
static class LEAD_VARS
{
public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images";
public const string OcrLEADRuntimeDir = @"C:\LEADTOOLS22\Bin\Common\OcrLEADRuntime";
}