GetFontName Method
Summary
gets the specific type of font used in the final document.
Syntax
C#
VB
Objective-C
C++
Java
- (nullable NSString *)fontNameForLanguage:(LTOcrLanguage)language
fontType:(LTOcrDocumentFontType)fontType
error:(NSError **)error
Parameters
languageName
The language name. See remarks for more information.
fontType
The type of font to get.
Return Value
The font name.
Example
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, false))
{
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:\Users\Public\Documents\LEADTOOLS Images";
public const string OcrLEADRuntimeDir = @"C:\LEADTOOLS 20\Bin\Common\OcrLEADRuntime";
}
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.Ocr
Imports Leadtools.Forms
Imports Leadtools.Document.Writer
Imports Leadtools.WinForms
Public Sub DocumentFontsTest()
Using codecs As New RasterCodecs()
Using ocrEngine As IOcrEngine = OcrEngineManager.CreateEngine(OcrEngineType.LEAD, False)
ocrEngine.Startup(codecs, Nothing, Nothing, LEAD_VARS.OcrLEADRuntimeDir)
Dim ocrDocumentManager As IOcrDocumentManager = ocrEngine.DocumentManager
Using ocrDocument As IOcrDocument = ocrEngine.DocumentManager.CreateDocument()
' Add a page to OCR
Dim ocrPage As IOcrPage = ocrDocument.Pages.AddPage(Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.tif"), Nothing)
ocrPage.AutoZone(Nothing)
ocrPage.Recognize(Nothing)
' 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, Nothing)
' Now change the fonts to something else
Dim newFonts As String() = ocrDocumentManager.GetFontNames(Nothing)
' 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(Nothing, 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, Nothing)
End Using
End Using
End Using
End Sub
Private Shared Sub ShowFonts(ocrDocumentManager As IOcrDocumentManager)
' Get the default fonts
' The default fonts will be used for all Latin languages
Dim fonts As String() = ocrDocumentManager.GetFontNames(Nothing)
' 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))
End Sub
Public NotInheritable Class LEAD_VARS
Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
Public Const OcrLEADRuntimeDir As String = "C:\LEADTOOLS 20\Bin\Common\OcrLEADRuntime"
End Class