{{< figure align=center src=“images/aspose_font-for-net.png” alt=“C# Load Font from File | Save CFF, TrueType, and Type1 Fonts”>}}

In digital typography, fonts define the visual style of characters. They are used in documents and web pages to stylize text. Each font file contains information about size, weight, style, and encoding. Because fonts are essential to many file formats, Aspose offers an API for manipulating and rendering popular font types, including TrueType, CFF, OpenType, and Type1. This article shows how to load fonts, save fonts, and extract font metrics in C#.

C# Font API to Load and Save Fonts from Files

Aspose.Font for .NET is an on‑premise API that lets you add font management features to C# applications. In addition to loading, saving, and extracting information, the API can render glyphs or text when needed.

Please either download the API or install it via NuGet.

PM> Install-Package Aspose.Font

Load or Save Font From File using C#

You can load a font from a file or byte array to access its data. Aspose.Font for .NET provides separate classes for each font type—CFF, TrueType, etc. Follow these steps:

Load and Save the CFF Font

The code sample below demonstrates loading and saving CFF fonts in C#.

{{< gist aspose-com-gists 10f0e5f274b436379dbc8fd4fb183fc5 “Examples-CSharp-WorkingWithCFFFonts-SaveCFFToDisc-1.cs” >}}

Load and Save TrueType Font

The code sample below demonstrates loading and saving TrueType fonts in C#.

{{< gist aspose-com-gists 10f0e5f274b436379dbc8fd4fb183fc5 “Examples-CSharp-WorkingWithTrueTypeAndOpenTypeFonts-SaveTTFToDisc-1.cs” >}}

Load and Save Type1 Font

The code sample below demonstrates loading and saving Type1 fonts in C#.

{{< gist aspose-com-gists 10f0e5f274b436379dbc8fd4fb183fc5 “Examples-CSharp-WorkingWithType1Fonts-LoadType1Fonts-1.cs” >}}

Extract Font Metrics using C#

Aspose.Font for .NET can retrieve metrics such as Ascender, Descender, TypoAscender, TypoDescender, and UnitsPerEm. Follow these steps:

  • Use the FontDefinition class to load a TrueType or Type1 font.
  • Open the font with the appropriate class (e.g., TtfFont or Type1Font).
  • Access the font’s metrics properties.

Extract Font Metrics from TrueType Font

{{< gist aspose-com-gists 10f0e5f274b436379dbc8fd4fb183fc5 “Examples-CSharp-WorkingWithTrueTypeAndOpenTypeFonts-GetFontMetrics-1.cs” >}}

Get Font Metrics from Type1 Font

{{< gist aspose-com-gists 10f0e5f274b436379dbc8fd4fb183fc5 “Examples-CSharp-WorkingWithType1Fonts-GetFontMetrics-1.cs” >}}

Detect Latin Symbols in Fonts using C#

You can detect Latin characters by decoding glyph codes with Aspose.Font for .NET. Steps:

  • Load the font using the FontDefinition class.
  • Decode the glyph ID with the DecodeToGid() method of the specific font class.

Detect Latin Symbols in TrueType Font

{{< gist aspose-com-gists 10f0e5f274b436379dbc8fd4fb183fc5 “Examples-CSharp-WorkingWithTrueTypeAndOpenTypeFonts-DetectLatinSymbolsSupport-1.cs” >}}

Detect Latin Symbols in Type1 Font

{{< gist aspose-com-gists 10f0e5f274b436379dbc8fd4fb183fc5 “Examples-CSharp-WorkingWithType1Fonts-DetectLatinSymbolsSupport-1.cs” >}}

C# Font API - Learning Resources

Explore more about loading, saving, converting, and manipulating fonts with Aspose.Font for .NET:

Conclusion

This article demonstrated how to programmatically load, save, and extract metrics from CFF, TrueType, and Type1 fonts using C#. With Aspose.Font for .NET, you can easily build applications that manipulate fonts. For any questions, visit our [free support forum][18].

See Also