WarningType

Inheritance: java.lang.Object

public class WarningType

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

Examples:

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 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 {
     /// 
     /// Called every time a warning occurs during loading/saving.
     /// 
     public void warning(WarningInfo info) {
         if (info.getWarningType() == WarningType.FONT_SUBSTITUTION)
             FontWarnings.warning(info);
     }

     public WarningInfoCollection FontWarnings = new WarningInfoCollection();
 }
 

Fields

FieldDescription
DATA_LOSSGeneric data loss, no specific code.
DATA_LOSS_CATEGORYSome text/char/image or other data will be missing from either the document tree following load, or from the created document following save.
FONT_EMBEDDINGLoss of embedded font information during document saving.
FONT_SUBSTITUTIONFont has been substituted.
HINTAdvises of a potential problem or suggests an improvement.
MAJOR_FORMATTING_LOSSGeneric major formatting loss, no specific code.
MAJOR_FORMATTING_LOSS_CATEGORYThe resulting document or a particular location in it might look substantially different compared to the original document.
MINOR_FORMATTING_LOSSGeneric minor formatting loss, no specific code.
MINOR_FORMATTING_LOSS_CATEGORYThe resulting document or a particular location in it might look somewhat different compared to the original document.
UNEXPECTED_CONTENTGeneric unexpected content, no specific code.
UNEXPECTED_CONTENT_CATEGORYSome content in the source document could not be recognized (i.e.
length

Methods

MethodDescription
fromName(String warningTypeName)
fromNames(Set warningTypeNames)
getName(int warningType)
getNames(int warningType)
getValues()
toString(int warningType)
toStringSet(int attr)

DATA_LOSS

public static int DATA_LOSS

Generic data loss, no specific code.

DATA_LOSS_CATEGORY

public static int DATA_LOSS_CATEGORY

Some text/char/image or other data will be missing from either the document tree following load, or from the created document following save.

FONT_EMBEDDING

public static int FONT_EMBEDDING

Loss of embedded font information during document saving.

FONT_SUBSTITUTION

public static int FONT_SUBSTITUTION

Font has been substituted.

HINT

public static int HINT

Advises of a potential problem or suggests an improvement.

MAJOR_FORMATTING_LOSS

public static int MAJOR_FORMATTING_LOSS

Generic major formatting loss, no specific code.

MAJOR_FORMATTING_LOSS_CATEGORY

public static int MAJOR_FORMATTING_LOSS_CATEGORY

The resulting document or a particular location in it might look substantially different compared to the original document.

MINOR_FORMATTING_LOSS

public static int MINOR_FORMATTING_LOSS

Generic minor formatting loss, no specific code.

MINOR_FORMATTING_LOSS_CATEGORY

public static int MINOR_FORMATTING_LOSS_CATEGORY

The resulting document or a particular location in it might look somewhat different compared to the original document.

UNEXPECTED_CONTENT

public static int UNEXPECTED_CONTENT

Generic unexpected content, no specific code.

UNEXPECTED_CONTENT_CATEGORY

public static int UNEXPECTED_CONTENT_CATEGORY

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.

length

public static int length

fromName(String warningTypeName)

public static int fromName(String warningTypeName)

Parameters:

ParameterTypeDescription
warningTypeNamejava.lang.String

Returns: int

fromNames(Set warningTypeNames)

public static int fromNames(Set warningTypeNames)

Parameters:

ParameterTypeDescription
warningTypeNamesjava.util.Set

Returns: int

getName(int warningType)

public static String getName(int warningType)

Parameters:

ParameterTypeDescription
warningTypeint

Returns: java.lang.String

getNames(int warningType)

public static Set getNames(int warningType)

Parameters:

ParameterTypeDescription
warningTypeint

Returns: java.util.Set

getValues()

public static int[] getValues()

Returns: int[]

toString(int warningType)

public static String toString(int warningType)

Parameters:

ParameterTypeDescription
warningTypeint

Returns: java.lang.String

toStringSet(int attr)

public static String toStringSet(int attr)

Parameters:

ParameterTypeDescription
attrint

Returns: java.lang.String