public class WarningInfoCollection
You can use this collection object as the simplest form of
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(); }
Constructor Summary |
---|
Property Getters/Setters Summary | ||
---|---|---|
int | getCount() | |
Gets the number of elements contained in the collection.
|
||
WarningInfo | get(int index) | |
Gets an item at the specified index.
|
Method Summary | ||
---|---|---|
void | clear() | |
Removes all elements from the collection.
|
||
java.util.Iterator<WarningInfo> | iterator() | |
Returns an iterator object that can be used to iterate over all items in the collection.
|
||
void | warning(WarningInfo info) | |
Implements the |
public int getCount()
public WarningInfo get(int index)
index
- Zero-based index of the item.public void clear()
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(); }
public java.util.Iterator<WarningInfo> iterator()
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(); }
public void warning(WarningInfo info)
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(); }