Click or drag to resize

WarningType Enumeration

Specifies the type of a warning that is issued by Aspose.Words during document loading or saving.

Namespace:  Aspose.Words
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 21.9.0

ExpandedSyntax

[FlagsAttribute]
public enum WarningType

ExpandedMembers

  Member nameValueDescription
DataLossCategory255 Some text/char/image or other data will be missing from either the document tree following load, or from the created document following save.
DataLoss1 Generic data loss, no specific code.
MajorFormattingLossCategory65280 The resulting document or a particular location in it might look substantially different compared to the original document.
MajorFormattingLoss256 Generic major formatting loss, no specific code.
MinorFormattingLossCategory16711680 The resulting document or a particular location in it might look somewhat different compared to the original document.
MinorFormattingLoss65536 Generic minor formatting loss, no specific code.
FontSubstitution131072 Font has been substituted.
FontEmbedding262144 Loss of embedded font information during document saving.
UnexpectedContentCategory251658240 Some content in the source document could not be recognized (i.e. is unsupported), this may or may not cause issues or result in data/formatting loss.
UnexpectedContent16777216 Generic unexpected content, no specific code.
Hint268435456 Advises of a potential problem or suggests an improvement.

ExpandedExamples

Shows how to set the property for finding the closest match for a missing font from the available font sources.
[Test]
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())
            Console.WriteLine(warnings.Current.Description);

    // We can also verify warnings in the collection and clear them.
    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.",
        substitutionWarningHandler.FontWarnings[0].Description);

    substitutionWarningHandler.FontWarnings.Clear();

    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)
            FontWarnings.Warning(info);
    }

    public WarningInfoCollection FontWarnings = new WarningInfoCollection();
}

ExpandedSee Also