com.aspose.words
Class WarningInfo

java.lang.Object
    extended by com.aspose.words.WarningInfo

public class WarningInfo 
extends java.lang.Object

Contains information about a warning that Aspose.Words issued during document loading or saving.

To learn more, visit the Programming with Documents documentation article.

You do not create instances of this class. Objects of this class are created and passed by Aspose.Words to the IWarningCallback.warning(com.aspose.words.WarningInfo) method.

Example:

Shows how to set the property for finding the closest match for a missing font from the available font sources.
public void enableFontSubstitution() throws Exception {
    // Open a document that contains text formatted with a font that does not exist in any of our font sources.
    Document doc = new Document(getMyDir() + "Missing font.docx");

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

    // Set a default font name and enable font substitution.
    FontSettings fontSettings = new FontSettings();
    fontSettings.getSubstitutionSettings().getDefaultFontSubstitution().setDefaultFontName("Arial");
    fontSettings.getSubstitutionSettings().getFontInfoSubstitution().setEnabled(true);

    // Original font metrics should be used after font substitution.
    doc.getLayoutOptions().setKeepOriginalFontMetrics(true);

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

    Iterator<WarningInfo> warnings = substitutionWarningHandler.FontWarnings.iterator();

    while (warnings.hasNext())
        System.out.println(warnings.next().getDescription());

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

    substitutionWarningHandler.FontWarnings.clear();

    Assert.assertTrue(substitutionWarningHandler.FontWarnings.getCount() == 0);
}

public static class HandleDocumentSubstitutionWarnings implements IWarningCallback {
    /// <summary>
    /// Called every time a warning occurs during loading/saving.
    /// </summary>
    public void warning(WarningInfo info) {
        if (info.getWarningType() == WarningType.FONT_SUBSTITUTION)
            FontWarnings.warning(info);
    }

    public WarningInfoCollection FontWarnings = new WarningInfoCollection();
}
See Also:
IWarningCallback

Property Getters/Setters Summary
java.lang.StringgetDescription()
           Returns the description of the warning.
intgetSource()
           Returns the source of the warning. The value of the property is WarningSource integer constant.
intgetWarningType()
           Returns the type of the warning. The value of the property is WarningType integer constant.
 

Property Getters/Setters Detail

getDescription

public java.lang.String getDescription()
Returns the description of the warning.

Example:

Shows how to set the property for finding the closest match for a missing font from the available font sources.
public void enableFontSubstitution() throws Exception {
    // Open a document that contains text formatted with a font that does not exist in any of our font sources.
    Document doc = new Document(getMyDir() + "Missing font.docx");

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

    // Set a default font name and enable font substitution.
    FontSettings fontSettings = new FontSettings();
    fontSettings.getSubstitutionSettings().getDefaultFontSubstitution().setDefaultFontName("Arial");
    fontSettings.getSubstitutionSettings().getFontInfoSubstitution().setEnabled(true);

    // Original font metrics should be used after font substitution.
    doc.getLayoutOptions().setKeepOriginalFontMetrics(true);

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

    Iterator<WarningInfo> warnings = substitutionWarningHandler.FontWarnings.iterator();

    while (warnings.hasNext())
        System.out.println(warnings.next().getDescription());

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

    substitutionWarningHandler.FontWarnings.clear();

    Assert.assertTrue(substitutionWarningHandler.FontWarnings.getCount() == 0);
}

public static class HandleDocumentSubstitutionWarnings implements IWarningCallback {
    /// <summary>
    /// Called every time a warning occurs during loading/saving.
    /// </summary>
    public void warning(WarningInfo info) {
        if (info.getWarningType() == WarningType.FONT_SUBSTITUTION)
            FontWarnings.warning(info);
    }

    public WarningInfoCollection FontWarnings = new WarningInfoCollection();
}

getSource

public int getSource()
Returns the source of the warning. The value of the property is WarningSource integer constant.

Example:

Shows how to work with the warning source.
Document doc = new Document(getMyDir() + "Emphases markdown warning.docx");

WarningInfoCollection warnings = new WarningInfoCollection();
doc.setWarningCallback(warnings);
doc.save(getArtifactsDir() + "DocumentBuilder.EmphasesWarningSourceMarkdown.md");

for (WarningInfo warningInfo : warnings) {
    if (warningInfo.getSource() == WarningSource.MARKDOWN)
        Assert.assertEquals("The (*, 0:11) cannot be properly written into Markdown.", warningInfo.getDescription());
}

getWarningType

public int getWarningType()
Returns the type of the warning. The value of the property is WarningType integer constant.

Example:

Shows how to set the property for finding the closest match for a missing font from the available font sources.
public void enableFontSubstitution() throws Exception {
    // Open a document that contains text formatted with a font that does not exist in any of our font sources.
    Document doc = new Document(getMyDir() + "Missing font.docx");

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

    // Set a default font name and enable font substitution.
    FontSettings fontSettings = new FontSettings();
    fontSettings.getSubstitutionSettings().getDefaultFontSubstitution().setDefaultFontName("Arial");
    fontSettings.getSubstitutionSettings().getFontInfoSubstitution().setEnabled(true);

    // Original font metrics should be used after font substitution.
    doc.getLayoutOptions().setKeepOriginalFontMetrics(true);

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

    Iterator<WarningInfo> warnings = substitutionWarningHandler.FontWarnings.iterator();

    while (warnings.hasNext())
        System.out.println(warnings.next().getDescription());

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

    substitutionWarningHandler.FontWarnings.clear();

    Assert.assertTrue(substitutionWarningHandler.FontWarnings.getCount() == 0);
}

public static class HandleDocumentSubstitutionWarnings implements IWarningCallback {
    /// <summary>
    /// Called every time a warning occurs during loading/saving.
    /// </summary>
    public void warning(WarningInfo info) {
        if (info.getWarningType() == WarningType.FONT_SUBSTITUTION)
            FontWarnings.warning(info);
    }

    public WarningInfoCollection FontWarnings = new WarningInfoCollection();
}

See Also:
          Aspose.Words Documentation - the home page for the Aspose.Words Product Documentation.
          Aspose.Words Support Forum - our preferred method of support.