FontInfoSubstitutionRule class

Font info substitution rule.

public class FontInfoSubstitutionRule : FontSubstitutionRule


Name Description
virtual Enabled { get; set; } Specifies whether the rule is enabled or not.


According to this rule Aspose.Words evaluates all the related fields in FontInfo (Panose, Sig etc) for the missing font and finds the closest match among the available font sources. If FontInfo is not available for the missing font then nothing will be done.


Shows how to set the property for finding the closest match for a missing font from the available font sources.

public void EnableFontSubstitution()
    // Open a document that contains text formatted with a font that does not exist in any of our font sources.
    Document doc = new Document(MyDir + "Missing font.docx");

    // Assign a callback for handling font substitution warnings.
    HandleDocumentSubstitutionWarnings substitutionWarningHandler = new HandleDocumentSubstitutionWarnings();
    doc.WarningCallback = substitutionWarningHandler;

    // Set a default font name and enable font substitution.
    FontSettings fontSettings = new FontSettings();
    fontSettings.SubstitutionSettings.DefaultFontSubstitution.DefaultFontName = "Arial";
    fontSettings.SubstitutionSettings.FontInfoSubstitution.Enabled = true;

    // We will get a font substitution warning if we save a document with a missing font.
    doc.FontSettings = fontSettings;
    doc.Save(ArtifactsDir + "FontSettings.EnableFontSubstitution.pdf");

    using (IEnumerator<WarningInfo> warnings = substitutionWarningHandler.FontWarnings.GetEnumerator())
        while (warnings.MoveNext())

    // We can also verify warnings in the collection and clear them.
    Assert.AreEqual(WarningSource.Layout, substitutionWarningHandler.FontWarnings[0].Source);
        "Font '28 Days Later' has not been found. Using 'Calibri' font instead. Reason: alternative name from document.",


    Assert.That(substitutionWarningHandler.FontWarnings, Is.Empty);

public class HandleDocumentSubstitutionWarnings : IWarningCallback
    /// <summary>
    /// Called every time a warning occurs during loading/saving.
    /// </summary>
    public void Warning(WarningInfo info)
        if (info.WarningType == WarningType.FontSubstitution)

    public WarningInfoCollection FontWarnings = new WarningInfoCollection();

See Also