com.aspose.words

Class WarningInfo

  • java.lang.Object
    • 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.

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.
@Test
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);

    // 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.
        @Test
        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);
        
            // 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.
      • 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.
        @Test
        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);
        
            // 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();
        }