FontInfoSubstitutionRule Class

Font info substitution rule.

Inheritance Hierarchy

Namespace:  Aspose.Words.Fonts
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.7.0


public class FontInfoSubstitutionRule : FontSubstitutionRule

The FontInfoSubstitutionRule type exposes the following members.


Public propertyCode exampleEnabled
Specifies whether the rule is enabled or not.
(Inherited from FontSubstitutionRule.)


Public methodEquals (Inherited from Object.)
Public methodGetHashCode (Inherited from Object.)
Public methodGetType (Inherited from Object.)
Public methodToString (Inherited from Object.)


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 font among the available font sources instead missing font.
public void EnableFontSubstitution()
    Document doc = new Document(MyDir + "Missing font.docx");

    // Assign a custom warning callback
    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;

    // When saving the document with the missing font, we should get a warning
    doc.FontSettings = fontSettings;
    doc.Save(ArtifactsDir + "Font.EnableFontSubstitution.pdf");

    // List all warnings using an enumerator
    using (IEnumerator<WarningInfo> warnings = substitutionWarningHandler.FontWarnings.GetEnumerator()) 
        while (warnings.MoveNext()) 

    // Warnings are stored in this format
    Assert.AreEqual(WarningSource.Layout, substitutionWarningHandler.FontWarnings[0].Source);
    Assert.AreEqual("Font '28 Days Later' has not been found. Using 'Calibri' font instead. Reason: alternative name from document.", 

    // The warning info collection can also be cleared like this

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

public class HandleDocumentSubstitutionWarnings : IWarningCallback
    /// <summary>
    /// Our callback only needs to implement the "Warning" method. This method is called whenever there is a
    /// potential issue during document processing. The callback can be set to listen for warnings generated during document
    /// load and/or document save.
    /// </summary>
    public void Warning(WarningInfo info)
        // We are only interested in fonts being substituted
        if (info.WarningType == WarningType.FontSubstitution)

    public WarningInfoCollection FontWarnings = new WarningInfoCollection();

See Also