java.lang.Object
com.aspose.words.WarningInfo
public class WarningInfo
You do not create instances of this class. Objects of this class are created
and passed by Aspose.Words to the Example:
@Test
public void enableFontSubstitution() throws Exception {
Document doc = new Document(getMyDir() + "Missing font.docx");
// Assign a custom warning callback
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);
// When saving the document with the missing font, we should get a warning
doc.setFontSettings(fontSettings);
doc.save(getArtifactsDir() + "Font.EnableFontSubstitution.pdf");
// List all warnings using an enumerator
Iterator<WarningInfo> warnings = substitutionWarningHandler.FontWarnings.iterator();
while (warnings.hasNext())
System.out.println(warnings.next().getDescription());
// Warnings are stored in this format
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());
// The warning info collection can also be cleared like this
substitutionWarningHandler.FontWarnings.clear();
Assert.assertEquals(substitutionWarningHandler.FontWarnings.getCount(), 0);
}
public static class HandleDocumentSubstitutionWarnings implements IWarningCallback {
/// <summary>
/// Our callback only needs to implement the "Warning" method. This method is called whenever there is a
/// potential issue during document processing. The callback can be set to listen for warnings generated during document
/// load and/or document save.
/// </summary>
public void warning(WarningInfo info) {
// We are only interested in fonts being substituted
if (info.getWarningType() == WarningType.FONT_SUBSTITUTION)
FontWarnings.warning(info);
}
public WarningInfoCollection FontWarnings = new WarningInfoCollection();
}
| Property Getters/Setters Summary | ||
|---|---|---|
java.lang.String | getDescription() | |
| Returns the description of the warning. | ||
int | getSource() | |
| Returns the source of the warning. The value of the property is WarningSource integer constant. | ||
int | getWarningType() | |
| 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() | |
Example:
Shows how to set the property for finding the closest match font among the available font sources instead missing font.
@Test
public void enableFontSubstitution() throws Exception {
Document doc = new Document(getMyDir() + "Missing font.docx");
// Assign a custom warning callback
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);
// When saving the document with the missing font, we should get a warning
doc.setFontSettings(fontSettings);
doc.save(getArtifactsDir() + "Font.EnableFontSubstitution.pdf");
// List all warnings using an enumerator
Iterator<WarningInfo> warnings = substitutionWarningHandler.FontWarnings.iterator();
while (warnings.hasNext())
System.out.println(warnings.next().getDescription());
// Warnings are stored in this format
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());
// The warning info collection can also be cleared like this
substitutionWarningHandler.FontWarnings.clear();
Assert.assertEquals(substitutionWarningHandler.FontWarnings.getCount(), 0);
}
public static class HandleDocumentSubstitutionWarnings implements IWarningCallback {
/// <summary>
/// Our callback only needs to implement the "Warning" method. This method is called whenever there is a
/// potential issue during document processing. The callback can be set to listen for warnings generated during document
/// load and/or document save.
/// </summary>
public void warning(WarningInfo info) {
// We are only interested in fonts being substituted
if (info.getWarningType() == WarningType.FONT_SUBSTITUTION)
FontWarnings.warning(info);
}
public WarningInfoCollection FontWarnings = new WarningInfoCollection();
}getSource | |
public int getSource() | |
getWarningType | |
public int getWarningType() | |
Example:
Shows how to set the property for finding the closest match font among the available font sources instead missing font.
@Test
public void enableFontSubstitution() throws Exception {
Document doc = new Document(getMyDir() + "Missing font.docx");
// Assign a custom warning callback
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);
// When saving the document with the missing font, we should get a warning
doc.setFontSettings(fontSettings);
doc.save(getArtifactsDir() + "Font.EnableFontSubstitution.pdf");
// List all warnings using an enumerator
Iterator<WarningInfo> warnings = substitutionWarningHandler.FontWarnings.iterator();
while (warnings.hasNext())
System.out.println(warnings.next().getDescription());
// Warnings are stored in this format
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());
// The warning info collection can also be cleared like this
substitutionWarningHandler.FontWarnings.clear();
Assert.assertEquals(substitutionWarningHandler.FontWarnings.getCount(), 0);
}
public static class HandleDocumentSubstitutionWarnings implements IWarningCallback {
/// <summary>
/// Our callback only needs to implement the "Warning" method. This method is called whenever there is a
/// potential issue during document processing. The callback can be set to listen for warnings generated during document
/// load and/or document save.
/// </summary>
public void warning(WarningInfo info) {
// We are only interested in fonts being substituted
if (info.getWarningType() == WarningType.FONT_SUBSTITUTION)
FontWarnings.warning(info);
}
public WarningInfoCollection FontWarnings = new WarningInfoCollection();
}