public class WarningType
Example:
@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();
}
Field Summary | ||
---|---|---|
static final 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.
|
||
static final int | DATA_LOSS | |
Generic data loss, no specific code.
|
||
static final int | MAJOR_FORMATTING_LOSS_CATEGORY | |
The resulting document or a particular location in it might look substantially different
compared to the original document.
|
||
static final int | MAJOR_FORMATTING_LOSS | |
Generic major formatting loss, no specific code.
|
||
static final int | MINOR_FORMATTING_LOSS_CATEGORY | |
The resulting document or a particular location in it might look somewhat different compared
to the original document.
|
||
static final int | MINOR_FORMATTING_LOSS | |
Generic minor formatting loss, no specific code.
|
||
static final int | FONT_SUBSTITUTION | |
Font has been substituted.
|
||
static final int | FONT_EMBEDDING | |
Loss of embedded font information during document saving.
|
||
static final 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.
|
||
static final int | UNEXPECTED_CONTENT | |
Generic unexpected content, no specific code.
|
||
static final int | HINT | |
Advises of a potential problem or suggests an improvement.
|
public static final int DATA_LOSS_CATEGORY
public static final int DATA_LOSS
public static final int MAJOR_FORMATTING_LOSS_CATEGORY
public static final int MAJOR_FORMATTING_LOSS
public static final int MINOR_FORMATTING_LOSS_CATEGORY
public static final int MINOR_FORMATTING_LOSS
public static final int FONT_SUBSTITUTION
public static final int FONT_EMBEDDING
public static final int UNEXPECTED_CONTENT_CATEGORY
public static final int UNEXPECTED_CONTENT
public static final int HINT