Loading Embedded OpenType (EOT) font files | .NET
Contents
[
Hide
Show
]Loading EOT fonts with Aspose.Font for .NET
Embedded OpenType (EOT) is a compact, web‑oriented font format originally introduced by Microsoft for use with Internet Explorer. Although its popularity has declined in favor of WOFF/WOFF2, many legacy web applications still rely on EOT files. The Aspose.Font library provides a pure .NET API that lets you read, modify, convert, and write EOT fonts without the need for a graphics subsystem.
What you need
| Requirement | Details |
|---|---|
| .NET Runtime | .NET 6.0 or later (the library also supports .NET Framework 4.6.2+) |
| Aspose.Font for .NET | Install via NuGet: dotnet add package Aspose.Font |
| IDE | Visual Studio 2022, VS Code, or any editor that supports C# |
| License | A valid Aspose.Font license is required for production use. The library can be evaluated in trial mode with a watermark. |
Loading an EOT Font
Step‑by‑step
- Initialize the file source. Point the application to the physical location of your font file. Using a verbatim string (@) handles the backslashes in Windows paths correctly.
- Load and open the font using the
Font.Openmethod that loads the binary data into an object. This is when the library validates if the file is corrupted or protected. - If the font was loaded correctly, you can extract technical data.
1using Aspose.Font;
2using Aspose.Font.Sources;
3
4// Path to the EOT file
5string eotPath = @"C:\Fonts\MyWebFont.eot";
6
7// Create a FontDefinition from the file source
8FontDefinition fontDef = new FontDefinition(
9 FontType.EOT, // Explicitly specify the format
10 new FileSystemFontSource(eotPath)
11);
12
13// Load the font into memory
14Font font = Font.Open(fontDef);
15
16// Verify that the font was loaded correctly
17Console.WriteLine($"Family: {font.FamilyName}");
18Console.WriteLine($"Style: {font.Style}");
19Console.WriteLine($"Units per EM: {font.UnitsPerEm}");Key points
FontDefinitionties a FontType enum to a FontSource implementation. It tells the system what kind of font it is (EOT, TTF, etc.) and where to find the raw data.FileSystemFontSourcereads a font from the local file system; other sources (stream, memory) are also supported. This tells the library to look for the font on your hard drive. Alternatively, you could use aByteContentFontSourceif the font was stored in a database or memory stream.- The returned
Fontobject gives read‑only access to all OpenType tables. Font.Open(fontDef) parses the binary data of the .eot file and creates an object in memory that understands the glyphs, kerning, and metadata.