java.lang.Object
com.aspose.words.CleanupOptions
public class CleanupOptions
- extends java.lang.Object
Allows to specify options for document cleaning.
Example:
Shows how to remove all unused styles and lists from a document.
Document doc = new Document();
// Insert some styles into a blank document
doc.getStyles().add(StyleType.LIST, "MyListStyle1");
doc.getStyles().add(StyleType.LIST, "MyListStyle2");
doc.getStyles().add(StyleType.CHARACTER, "MyParagraphStyle1");
doc.getStyles().add(StyleType.CHARACTER, "MyParagraphStyle2");
// Combined with the built in styles, the document now has 8 styles in total,
// but all 4 of the ones we added count as unused
Assert.assertEquals(8, doc.getStyles().getCount());
// A character style counts as used when the document contains text in that style
DocumentBuilder builder = new DocumentBuilder(doc);
builder.getFont().setStyle(doc.getStyles().get("MyParagraphStyle1"));
builder.writeln("Hello world!");
// A list style is also "used" when there is a list that uses it
List list = doc.getLists().add(doc.getStyles().get("MyListStyle1"));
builder.getListFormat().setList(list);
builder.writeln("Item 1");
builder.writeln("Item 2");
// The Cleanup() method, when configured with a CleanupOptions object, can target unused styles and remove them
CleanupOptions cleanupOptions = new CleanupOptions();
cleanupOptions.setUnusedLists(true);
cleanupOptions.setUnusedStyles(true);
// We've added 4 styles and used 2 of them, so the other two will be removed when this method is called
doc.cleanup(cleanupOptions);
Assert.assertEquals(6, doc.getStyles().getCount());
Property Getters/Setters Summary |
boolean | getDuplicateStyle() | |
void | setDuplicateStyle(boolean value) | |
|
Gets/sets a flag indicating whether duplicate styles should be removed from document.
Default value is false.
|
boolean | getUnusedLists() | |
void | setUnusedLists(boolean value) | |
|
Specifies whether unused list and list definitions should be removed from document.
Default value is true.
|
boolean | getUnusedStyles() | |
void | setUnusedStyles(boolean value) | |
|
Specifies whether unused styles should be removed from document.
Default value is true.
|
CleanupOptions
public CleanupOptions()
-
Property Getters/Setters Detail |
getDuplicateStyle/setDuplicateStyle | |
public boolean getDuplicateStyle() / public void setDuplicateStyle(boolean value)
|
-
Gets/sets a flag indicating whether duplicate styles should be removed from document.
Default value is false.
getUnusedLists/setUnusedLists | |
public boolean getUnusedLists() / public void setUnusedLists(boolean value)
|
-
Specifies whether unused list and list definitions should be removed from document.
Default value is true.
Example:
Shows how to remove all unused styles and lists from a document.
Document doc = new Document();
// Insert some styles into a blank document
doc.getStyles().add(StyleType.LIST, "MyListStyle1");
doc.getStyles().add(StyleType.LIST, "MyListStyle2");
doc.getStyles().add(StyleType.CHARACTER, "MyParagraphStyle1");
doc.getStyles().add(StyleType.CHARACTER, "MyParagraphStyle2");
// Combined with the built in styles, the document now has 8 styles in total,
// but all 4 of the ones we added count as unused
Assert.assertEquals(8, doc.getStyles().getCount());
// A character style counts as used when the document contains text in that style
DocumentBuilder builder = new DocumentBuilder(doc);
builder.getFont().setStyle(doc.getStyles().get("MyParagraphStyle1"));
builder.writeln("Hello world!");
// A list style is also "used" when there is a list that uses it
List list = doc.getLists().add(doc.getStyles().get("MyListStyle1"));
builder.getListFormat().setList(list);
builder.writeln("Item 1");
builder.writeln("Item 2");
// The Cleanup() method, when configured with a CleanupOptions object, can target unused styles and remove them
CleanupOptions cleanupOptions = new CleanupOptions();
cleanupOptions.setUnusedLists(true);
cleanupOptions.setUnusedStyles(true);
// We've added 4 styles and used 2 of them, so the other two will be removed when this method is called
doc.cleanup(cleanupOptions);
Assert.assertEquals(6, doc.getStyles().getCount());
getUnusedStyles/setUnusedStyles | |
public boolean getUnusedStyles() / public void setUnusedStyles(boolean value)
|
-
Specifies whether unused styles should be removed from document.
Default value is true.
Example:
Shows how to remove all unused styles and lists from a document.
Document doc = new Document();
// Insert some styles into a blank document
doc.getStyles().add(StyleType.LIST, "MyListStyle1");
doc.getStyles().add(StyleType.LIST, "MyListStyle2");
doc.getStyles().add(StyleType.CHARACTER, "MyParagraphStyle1");
doc.getStyles().add(StyleType.CHARACTER, "MyParagraphStyle2");
// Combined with the built in styles, the document now has 8 styles in total,
// but all 4 of the ones we added count as unused
Assert.assertEquals(8, doc.getStyles().getCount());
// A character style counts as used when the document contains text in that style
DocumentBuilder builder = new DocumentBuilder(doc);
builder.getFont().setStyle(doc.getStyles().get("MyParagraphStyle1"));
builder.writeln("Hello world!");
// A list style is also "used" when there is a list that uses it
List list = doc.getLists().add(doc.getStyles().get("MyListStyle1"));
builder.getListFormat().setList(list);
builder.writeln("Item 1");
builder.writeln("Item 2");
// The Cleanup() method, when configured with a CleanupOptions object, can target unused styles and remove them
CleanupOptions cleanupOptions = new CleanupOptions();
cleanupOptions.setUnusedLists(true);
cleanupOptions.setUnusedStyles(true);
// We've added 4 styles and used 2 of them, so the other two will be removed when this method is called
doc.cleanup(cleanupOptions);
Assert.assertEquals(6, doc.getStyles().getCount());
See Also:
Aspose.Words Documentation - the home page for the Aspose.Words Product Documentation.
Aspose.Words Support Forum - our preferred method of support.