FontInfoCollection class

Represents a collection of fonts used in a document.

public class FontInfoCollection : IEnumerable<FontInfo>


Name Description
Count { get; } Gets the number of elements contained in the collection.
EmbedSystemFonts { get; set; } Specifies whether or not to embed System fonts into the document. Default value for this property is false.
EmbedTrueTypeFonts { get; set; } Specifies whether or not to embed TrueType fonts in a document when it is saved. Default value for this property is false.
Item { get; } Gets a font with the specified name. (2 indexers)
SaveSubsetFonts { get; set; } Specifies whether or not to save a subset of the embedded TrueType fonts with the document. Default value for this property is false.


Name Description
Contains(string) Determines whether the collection contains a font with the given name.
GetEnumerator() Returns an enumerator object that can be used to iterate over all items in the collection.


Items are FontInfo objects.

You do not create instances of this class directly. Use the FontInfos property to access the collection of fonts defined in the document.


Shows how to print the details of what fonts are present in a document.

Document doc = new Document(MyDir + "Embedded font.docx");

FontInfoCollection allFonts = doc.FontInfos;
// Print all the used and unused fonts in the document.
for (int i = 0; i < allFonts.Count; i++)
    Console.WriteLine($"Font index #{i}");
    Console.WriteLine($"\tName: {allFonts[i].Name}");
    Console.WriteLine($"\tIs {(allFonts[i].IsTrueType ? "" : "not ")}a trueType font");

Shows how to save a document with embedded TrueType fonts.

Document doc = new Document(MyDir + "Document.docx");

FontInfoCollection fontInfos = doc.FontInfos;
fontInfos.EmbedTrueTypeFonts = embedAllFonts;
fontInfos.EmbedSystemFonts = embedAllFonts;
fontInfos.SaveSubsetFonts = embedAllFonts;

doc.Save(ArtifactsDir + "Font.FontInfoCollection.docx");

if (embedAllFonts)
    Assert.That(25000, Is.LessThan(new FileInfo(ArtifactsDir + "Font.FontInfoCollection.docx").Length));
    Assert.That(15000, Is.AtLeast(new FileInfo(ArtifactsDir + "Font.FontInfoCollection.docx").Length));

See Also