Fonts
Fonts
This guide shows how to inspect the fonts referenced in a document, extract embedded font data, and control TrueType font embedding on save with Aspose.Words FOSS for .NET. Aspose.Words FOSS for .NET tracks every font referenced by a loaded document through FontInfoCollection, and exposes per-font metadata, embedded font extraction, and embedding-on-save controls through FontInfo. Document.FontSettings and LoadOptions.FontSettings provide the (deliberately minimal, in this edition) FontSettings entry point.
Inspecting Fonts Used in a Document
DocumentBase.FontInfos (inherited by Document) returns a FontInfoCollection describing every font referenced anywhere in the document. Index into it by name (e.g. fontInfos["Arial"]), test whether it exists with Contains(name), count them with Count, or enumerate the whole collection via GetEnumerator().
Font Properties and Classification
Each FontInfo describes one font: Name and AltName identify it, Family classifies it via the FontFamily enum (Auto, Roman, Swiss, Modern, Script, Decorative), Pitch reports its FontPitch (Default, Fixed, Variable), and IsTrueType, Charset, and Panose expose lower-level font-matching data.
Embedded Font Extraction
If a document has embedded fonts, FontInfo.GetEmbeddedFont(format, style) returns the raw embedded font bytes for a given EmbeddedFontFormat (EmbeddedOpenType or OpenType) and EmbeddedFontStyle (Regular, Bold, Italic, BoldItalic). GetEmbeddedFontAsOpenType(style) returns the font converted to OpenType format directly, regardless of how it was originally embedded.
Font Embedding Licensing Rights
Before extracting or re-embedding a font, check FontInfo.EmbeddingLicensingRights, a FontEmbeddingLicensingRights object. EmbeddingUsagePermissions reports the license level via the FontEmbeddingUsagePermissions enum (Installable, RestrictedLicense, PrintAndPreview, Editable), while NoSubsetting and BitmapEmbeddingOnly flag further restrictions set by the font vendor.
Controlling Font Embedding on Save
FontInfoCollection also carries document-level embedding switches: set EmbedTrueTypeFonts to true to embed every TrueType font used in the document when it’s saved, EmbedSystemFonts to include fonts normally assumed to be present on any system, and SaveSubsetFonts to embed only the glyphs actually used rather than the complete font.
FontSettings Scope in This Edition
Document.FontSettings and LoadOptions.FontSettings both return a FontSettings object, and FontSettings.DefaultInstance exposes a shared default instance. In this FOSS edition, FontSettings’ API surface is limited to that default-instance property — folder-based and system font-source resolution, which elsewhere in Aspose.Words is used to substitute or resolve fonts for page layout and rendering, is not present, since page layout and rendering are outside this edition’s scope. Font handling here means metadata inspection and embedding, not font substitution for rendering.
Tips and Best Practices
- Always check
FontInfo.EmbeddingLicensingRights.EmbeddingUsagePermissionsbefore extracting or redistributing an embedded font — some fonts are licensedRestrictedLicenseorPrintAndPreviewonly. - Use
GetEmbeddedFontAsOpenType()when you need a consistent output format regardless of how the source document embedded the font (EmbeddedOpenTypevsOpenType). - Set
FontInfoCollection.SaveSubsetFontstotrueto reduce output file size when embedding fonts that use only a handful of glyphs. FontInfoCollection.Contains(name)is cheaper than indexing in and handling a failed lookup (e.g.fontInfos[name]) when you only need to test for a font’s presence.
Common Issues
| Issue | Cause | Fix |
|---|---|---|
GetEmbeddedFont() returns no usable data | The referenced font isn’t actually embedded in the document | Check the document’s embedding settings before assuming font data is present |
Indexing into FontInfoCollection by name finds nothing | The font name doesn’t match exactly, including case | Enumerate FontInfoCollection with GetEnumerator() to confirm the exact Name string |
| Expected font substitution/resolution APIs are missing | Folder- and system-based font source resolution isn’t implemented in this FOSS edition | Use FontInfo/FontInfoCollection for metadata and embedding only; font substitution for rendering isn’t part of this edition’s scope |
FAQ
How do I list every font a document references?
Enumerate Document.FontInfos (a FontInfoCollection) via GetEnumerator(), or index into it by name to look up a specific one (e.g. fontInfos["Arial"]).
Can I pull the raw bytes of an embedded font out of a document?
Yes, if the font is embedded — call FontInfo.GetEmbeddedFont(format, style) for the original embedded format, or GetEmbeddedFontAsOpenType(style) to normalize the result to OpenType.
How do I make sure fonts are embedded when I save a document?
Set FontInfoCollection.EmbedTrueTypeFonts to true before saving; add EmbedSystemFonts if you also need fonts assumed to be present on any system, and SaveSubsetFonts to embed only the glyphs in use.
Does this edition support resolving fonts from a custom folder for rendering?
No — folder- and system-based font source resolution (FontSettings source configuration) isn’t implemented here, since it exists to serve page layout and rendering, which are outside this FOSS edition’s scope.
What does FontEmbeddingLicensingRights.NoSubsetting mean?
It’s a licensing flag reported by the font vendor’s embedding rights: when true, the font may not be subsetted to only the glyphs in use.
API Reference Summary
| Class / Method | Description |
|---|---|
FontInfoCollection | Fonts referenced in a document; indexer by name (fontInfos[name]), Contains(), Count, GetEnumerator(), plus EmbedTrueTypeFonts/EmbedSystemFonts/SaveSubsetFonts |
FontInfo | One font’s metadata: Name, AltName, Family, Pitch, IsTrueType, Charset, Panose, EmbeddingLicensingRights |
FontInfo.GetEmbeddedFont() / GetEmbeddedFontAsOpenType() | Extract embedded font bytes |
EmbeddedFontFormat / EmbeddedFontStyle | Enums identifying an embedded font’s format and style variant |
FontEmbeddingLicensingRights / FontEmbeddingUsagePermissions | Embedding license restrictions reported per font |
FontSettings | Minimal font-settings entry point (Document.FontSettings, LoadOptions.FontSettings); no font-source resolution in this edition |