WarningInfoCollection class

Represents a typed collection of WarningInfo objects.

public class WarningInfoCollection : IEnumerable<WarningInfo>, IWarningCallback


Name Description
WarningInfoCollection() The default constructor.


Name Description
Count { get; } Gets the number of elements contained in the collection.
Item { get; } Gets an item at the specified index.


Name Description
Clear() Removes all elements from the collection.
GetEnumerator() Returns an enumerator object that can be used to iterate over all items in the collection.
Warning(WarningInfo) Implements the IWarningCallback interface. Adds a warning to this collection.


You can use this collection object as the simplest form of IWarningCallback implementation to gather all warnings that Aspose.Words generates during a load or save operation. Create an instance of this class and assign it to the WarningCallback or WarningCallback property.


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