com.aspose.words
Class CustomDocumentProperties

java.lang.Object
  extended by DocumentPropertyCollection
      extended by com.aspose.words.CustomDocumentProperties
All Implemented Interfaces:
java.lang.Iterable

public class CustomDocumentProperties 
extends DocumentPropertyCollection

A collection of custom document properties.

Each DocumentProperty object represents a custom property of a container document.

The names of the properties are case-insensitive.

The properties in the collection are sorted alphabetically by name.

Example:

Shows how to work with custom document properties.
Document doc = new Document(getMyDir() + "Properties.docx");

// A document's built in properties contains a set of predetermined keys
// with values such as the author's name or document's word count
// We can add our own keys and values to a custom properties collection also
// Before we add a custom property, we need to make sure that one with the same name doesn't already exist
Assert.assertEquals("Value of custom document property", doc.getCustomDocumentProperties().get("CustomProperty").toString());

doc.getCustomDocumentProperties().add("CustomProperty2", "Value of custom document property #2");

// Iterate over all the custom document properties
System.out.println("Custom Properties:");
for (DocumentProperty customDocumentProperty : (Iterable<DocumentProperty>) doc.getCustomDocumentProperties()) {
    System.out.println(customDocumentProperty.getName());
    System.out.println("\tType:\t{customDocumentProperty.Type}");
    System.out.println("\tValue:\t\"{customDocumentProperty.Value}\"");
}
See Also:
Document, Document.BuiltInDocumentProperties, Document.CustomDocumentProperties

Property Getters/Setters Summary
intgetCount()→ inherited from DocumentPropertyCollection
           Gets number of items in the collection.
DocumentPropertyget(int index)→ inherited from DocumentPropertyCollection
           Returns a DocumentProperty object by index.
DocumentPropertyget(java.lang.String name)→ inherited from DocumentPropertyCollection
           Returns a DocumentProperty object by the name of the property.
 
Method Summary
DocumentPropertyadd(java.lang.String name, boolean value)
           Creates a new custom document property of the PropertyType.Boolean data type.
DocumentPropertyadd(java.lang.String name, double value)
           Creates a new custom document property of the PropertyType.Float data type.
DocumentPropertyadd(java.lang.String name, int value)
           Creates a new custom document property of the PropertyType.Number data type.
DocumentPropertyadd(java.lang.String name, java.lang.String value)
           Creates a new custom document property of the PropertyType.String data type.
DocumentPropertyadd(java.lang.String name, java.util.Date value)
           Creates a new custom document property of the PropertyType.DateTime data type.
DocumentPropertyaddLinkToContent(java.lang.String name, java.lang.String linkSource)
           Creates a new linked to content custom document property.
voidclear()→ inherited from DocumentPropertyCollection
           Removes all properties from the collection.
booleancontains(java.lang.String name)→ inherited from DocumentPropertyCollection
           Returns true if a property with the specified name exists in the collection.
intindexOf(java.lang.String name)→ inherited from DocumentPropertyCollection
           Gets the index of a property by name.
java.util.Iterator<DocumentProperty>iterator()→ inherited from DocumentPropertyCollection
           Returns an iterator object that can be used to iterate over all items in the collection.
voidremove(java.lang.String name)→ inherited from DocumentPropertyCollection
           Removes a property with the specified name from the collection.
voidremoveAt(int index)→ inherited from DocumentPropertyCollection
           Removes a property at the specified index.
 

Property Getters/Setters Detail

getCount

→ inherited from DocumentPropertyCollection
public int getCount()
Gets number of items in the collection.

Example:

Shows how to work with custom document properties.
Document doc = new Document(getMyDir() + "Properties.docx");

// A document's built in properties contains a set of predetermined keys
// with values such as the author's name or document's word count
// We can add our own keys and values to a custom properties collection also
// Before we add a custom property, we need to make sure that one with the same name doesn't already exist
Assert.assertEquals("Value of custom document property", doc.getCustomDocumentProperties().get("CustomProperty").toString());

doc.getCustomDocumentProperties().add("CustomProperty2", "Value of custom document property #2");

// Iterate over all the custom document properties
System.out.println("Custom Properties:");
for (DocumentProperty customDocumentProperty : (Iterable<DocumentProperty>) doc.getCustomDocumentProperties()) {
    System.out.println(customDocumentProperty.getName());
    System.out.println("\tType:\t{customDocumentProperty.Type}");
    System.out.println("\tValue:\t\"{customDocumentProperty.Value}\"");
}

get

→ inherited from DocumentPropertyCollection
public DocumentProperty get(int index)
Returns a DocumentProperty object by index.

Note: In Java this method is slow because iterates over all nodes.

Parameters:
index - Zero-based index of the DocumentProperty to retrieve.

Example:

Shows how to work with custom document properties.
Document doc = new Document(getMyDir() + "Properties.docx");

// A document's built in properties contains a set of predetermined keys
// with values such as the author's name or document's word count
// We can add our own keys and values to a custom properties collection also
// Before we add a custom property, we need to make sure that one with the same name doesn't already exist
Assert.assertEquals("Value of custom document property", doc.getCustomDocumentProperties().get("CustomProperty").toString());

doc.getCustomDocumentProperties().add("CustomProperty2", "Value of custom document property #2");

// Iterate over all the custom document properties
System.out.println("Custom Properties:");
for (DocumentProperty customDocumentProperty : (Iterable<DocumentProperty>) doc.getCustomDocumentProperties()) {
    System.out.println(customDocumentProperty.getName());
    System.out.println("\tType:\t{customDocumentProperty.Type}");
    System.out.println("\tValue:\t\"{customDocumentProperty.Value}\"");
}

get

→ inherited from DocumentPropertyCollection
public DocumentProperty get(java.lang.String name)
Returns a DocumentProperty object by the name of the property.

Returns null if a property with the specified name is not found.

Parameters:
name - The case-insensitive name of the property to retrieve.

Example:

Shows how to create a custom document property with the value of a date and time.
Document doc = new Document();

doc.getCustomDocumentProperties().add("AuthorizedDate", new Date());

System.out.println("Document authorized on {doc.CustomDocumentProperties[");

Method Detail

add

public DocumentProperty add(java.lang.String name, boolean value)
Creates a new custom document property of the PropertyType.Boolean data type.
Parameters:
name - The name of the property.
value - The value of the property.
Returns:
The newly created property object.

Example:

Shows how to add custom properties to a document.
Document doc = new Document();
CustomDocumentProperties properties = doc.getCustomDocumentProperties();

// The custom property collection will be empty by default
Assert.assertEquals(0, properties.getCount());

// We can populate it with key/value pairs with a variety of value types
properties.add("Authorized", true);
properties.add("Authorized By", "John Doe");
properties.add("Authorized Date", new Date());
properties.add("Authorized Revision", doc.getBuiltInDocumentProperties().getRevisionNumber());
properties.add("Authorized Amount", 123.45);

// Custom properties are automatically sorted in alphabetic order
Assert.assertEquals(properties.indexOf("Authorized Amount"), 1);
Assert.assertEquals(properties.getCount(), 5);

// Enumerate and print all custom properties
Iterator<DocumentProperty> enumerator = properties.iterator();
try {
    while (enumerator.hasNext()) {
        DocumentProperty property = enumerator.next();
        System.out.println(MessageFormat.format("Name: \"{0}\", Type: \"{1}\", Value: \"{2}\"", property.getName(), property.getType(), property.getValue()));
    }
} finally {
    if (enumerator != null) enumerator.remove();
}

// We can view/edit custom properties by opening the document and looking in File > Properties > Advanced Properties > Custom
doc.save(getArtifactsDir() + "Properties.DocumentPropertyCollection.docx");

// We can remove elements from the property collection by index or by name
properties.removeAt(1);
Assert.assertFalse(properties.contains("Authorized Amount"));
Assert.assertEquals(properties.getCount(), 4);

properties.remove("Authorized Revision");
Assert.assertFalse(properties.contains("Authorized Revision"));
Assert.assertEquals(properties.getCount(), 3);

// We can also empty the entire custom property collection at once
properties.clear();
Assert.assertEquals(properties.getCount(), 0);

add

public DocumentProperty add(java.lang.String name, double value)
Creates a new custom document property of the PropertyType.Float data type.
Parameters:
name - The name of the property.
value - The value of the property.
Returns:
The newly created property object.

Example:

Shows how to add custom properties to a document.
Document doc = new Document();
CustomDocumentProperties properties = doc.getCustomDocumentProperties();

// The custom property collection will be empty by default
Assert.assertEquals(0, properties.getCount());

// We can populate it with key/value pairs with a variety of value types
properties.add("Authorized", true);
properties.add("Authorized By", "John Doe");
properties.add("Authorized Date", new Date());
properties.add("Authorized Revision", doc.getBuiltInDocumentProperties().getRevisionNumber());
properties.add("Authorized Amount", 123.45);

// Custom properties are automatically sorted in alphabetic order
Assert.assertEquals(properties.indexOf("Authorized Amount"), 1);
Assert.assertEquals(properties.getCount(), 5);

// Enumerate and print all custom properties
Iterator<DocumentProperty> enumerator = properties.iterator();
try {
    while (enumerator.hasNext()) {
        DocumentProperty property = enumerator.next();
        System.out.println(MessageFormat.format("Name: \"{0}\", Type: \"{1}\", Value: \"{2}\"", property.getName(), property.getType(), property.getValue()));
    }
} finally {
    if (enumerator != null) enumerator.remove();
}

// We can view/edit custom properties by opening the document and looking in File > Properties > Advanced Properties > Custom
doc.save(getArtifactsDir() + "Properties.DocumentPropertyCollection.docx");

// We can remove elements from the property collection by index or by name
properties.removeAt(1);
Assert.assertFalse(properties.contains("Authorized Amount"));
Assert.assertEquals(properties.getCount(), 4);

properties.remove("Authorized Revision");
Assert.assertFalse(properties.contains("Authorized Revision"));
Assert.assertEquals(properties.getCount(), 3);

// We can also empty the entire custom property collection at once
properties.clear();
Assert.assertEquals(properties.getCount(), 0);

add

public DocumentProperty add(java.lang.String name, int value)
Creates a new custom document property of the PropertyType.Number data type.
Parameters:
name - The name of the property.
value - The value of the property.
Returns:
The newly created property object.

Example:

Shows how to add custom properties to a document.
Document doc = new Document();
CustomDocumentProperties properties = doc.getCustomDocumentProperties();

// The custom property collection will be empty by default
Assert.assertEquals(0, properties.getCount());

// We can populate it with key/value pairs with a variety of value types
properties.add("Authorized", true);
properties.add("Authorized By", "John Doe");
properties.add("Authorized Date", new Date());
properties.add("Authorized Revision", doc.getBuiltInDocumentProperties().getRevisionNumber());
properties.add("Authorized Amount", 123.45);

// Custom properties are automatically sorted in alphabetic order
Assert.assertEquals(properties.indexOf("Authorized Amount"), 1);
Assert.assertEquals(properties.getCount(), 5);

// Enumerate and print all custom properties
Iterator<DocumentProperty> enumerator = properties.iterator();
try {
    while (enumerator.hasNext()) {
        DocumentProperty property = enumerator.next();
        System.out.println(MessageFormat.format("Name: \"{0}\", Type: \"{1}\", Value: \"{2}\"", property.getName(), property.getType(), property.getValue()));
    }
} finally {
    if (enumerator != null) enumerator.remove();
}

// We can view/edit custom properties by opening the document and looking in File > Properties > Advanced Properties > Custom
doc.save(getArtifactsDir() + "Properties.DocumentPropertyCollection.docx");

// We can remove elements from the property collection by index or by name
properties.removeAt(1);
Assert.assertFalse(properties.contains("Authorized Amount"));
Assert.assertEquals(properties.getCount(), 4);

properties.remove("Authorized Revision");
Assert.assertFalse(properties.contains("Authorized Revision"));
Assert.assertEquals(properties.getCount(), 3);

// We can also empty the entire custom property collection at once
properties.clear();
Assert.assertEquals(properties.getCount(), 0);

add

public DocumentProperty add(java.lang.String name, java.lang.String value)
Creates a new custom document property of the PropertyType.String data type.
Parameters:
name - The name of the property.
value - The value of the property.
Returns:
The newly created property object.

Example:

Shows how to add custom properties to a document.
Document doc = new Document();
CustomDocumentProperties properties = doc.getCustomDocumentProperties();

// The custom property collection will be empty by default
Assert.assertEquals(0, properties.getCount());

// We can populate it with key/value pairs with a variety of value types
properties.add("Authorized", true);
properties.add("Authorized By", "John Doe");
properties.add("Authorized Date", new Date());
properties.add("Authorized Revision", doc.getBuiltInDocumentProperties().getRevisionNumber());
properties.add("Authorized Amount", 123.45);

// Custom properties are automatically sorted in alphabetic order
Assert.assertEquals(properties.indexOf("Authorized Amount"), 1);
Assert.assertEquals(properties.getCount(), 5);

// Enumerate and print all custom properties
Iterator<DocumentProperty> enumerator = properties.iterator();
try {
    while (enumerator.hasNext()) {
        DocumentProperty property = enumerator.next();
        System.out.println(MessageFormat.format("Name: \"{0}\", Type: \"{1}\", Value: \"{2}\"", property.getName(), property.getType(), property.getValue()));
    }
} finally {
    if (enumerator != null) enumerator.remove();
}

// We can view/edit custom properties by opening the document and looking in File > Properties > Advanced Properties > Custom
doc.save(getArtifactsDir() + "Properties.DocumentPropertyCollection.docx");

// We can remove elements from the property collection by index or by name
properties.removeAt(1);
Assert.assertFalse(properties.contains("Authorized Amount"));
Assert.assertEquals(properties.getCount(), 4);

properties.remove("Authorized Revision");
Assert.assertFalse(properties.contains("Authorized Revision"));
Assert.assertEquals(properties.getCount(), 3);

// We can also empty the entire custom property collection at once
properties.clear();
Assert.assertEquals(properties.getCount(), 0);

add

public DocumentProperty add(java.lang.String name, java.util.Date value)
Creates a new custom document property of the PropertyType.DateTime data type.
Parameters:
name - The name of the property.
value - The value of the property.
Returns:
The newly created property object.

Example:

Shows how to add custom properties to a document.
Document doc = new Document();
CustomDocumentProperties properties = doc.getCustomDocumentProperties();

// The custom property collection will be empty by default
Assert.assertEquals(0, properties.getCount());

// We can populate it with key/value pairs with a variety of value types
properties.add("Authorized", true);
properties.add("Authorized By", "John Doe");
properties.add("Authorized Date", new Date());
properties.add("Authorized Revision", doc.getBuiltInDocumentProperties().getRevisionNumber());
properties.add("Authorized Amount", 123.45);

// Custom properties are automatically sorted in alphabetic order
Assert.assertEquals(properties.indexOf("Authorized Amount"), 1);
Assert.assertEquals(properties.getCount(), 5);

// Enumerate and print all custom properties
Iterator<DocumentProperty> enumerator = properties.iterator();
try {
    while (enumerator.hasNext()) {
        DocumentProperty property = enumerator.next();
        System.out.println(MessageFormat.format("Name: \"{0}\", Type: \"{1}\", Value: \"{2}\"", property.getName(), property.getType(), property.getValue()));
    }
} finally {
    if (enumerator != null) enumerator.remove();
}

// We can view/edit custom properties by opening the document and looking in File > Properties > Advanced Properties > Custom
doc.save(getArtifactsDir() + "Properties.DocumentPropertyCollection.docx");

// We can remove elements from the property collection by index or by name
properties.removeAt(1);
Assert.assertFalse(properties.contains("Authorized Amount"));
Assert.assertEquals(properties.getCount(), 4);

properties.remove("Authorized Revision");
Assert.assertFalse(properties.contains("Authorized Revision"));
Assert.assertEquals(properties.getCount(), 3);

// We can also empty the entire custom property collection at once
properties.clear();
Assert.assertEquals(properties.getCount(), 0);

Example:

Shows how to create a custom document property with the value of a date and time.
Document doc = new Document();

doc.getCustomDocumentProperties().add("AuthorizedDate", new Date());

System.out.println("Document authorized on {doc.CustomDocumentProperties[");

addLinkToContent

public DocumentProperty addLinkToContent(java.lang.String name, java.lang.String linkSource)
                                 throws java.lang.Exception
Creates a new linked to content custom document property.
Parameters:
name - The name of the property.
linkSource - The source of the property.
Returns:
The newly created property object or null when the linkSource is invalid.

Example:

Shows how to link a custom document property to a bookmark.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.startBookmark("MyBookmark");
builder.write("MyBookmark contents.");
builder.endBookmark("MyBookmark");

// Add linked to content property
CustomDocumentProperties customProperties = doc.getCustomDocumentProperties();
DocumentProperty customProperty = customProperties.addLinkToContent("Bookmark", "MyBookmark");

// Check whether the property is linked to content
Assert.assertEquals(true, customProperty.isLinkToContent());
Assert.assertEquals("MyBookmark", customProperty.getLinkSource());
Assert.assertEquals("MyBookmark contents.", customProperty.getValue());

doc.save(getArtifactsDir() + "Properties.LinkCustomDocumentPropertiesToBookmark.docx");

clear

→ inherited from DocumentPropertyCollection
public void clear()
Removes all properties from the collection.

Example:

Shows how to add custom properties to a document.
Document doc = new Document();
CustomDocumentProperties properties = doc.getCustomDocumentProperties();

// The custom property collection will be empty by default
Assert.assertEquals(0, properties.getCount());

// We can populate it with key/value pairs with a variety of value types
properties.add("Authorized", true);
properties.add("Authorized By", "John Doe");
properties.add("Authorized Date", new Date());
properties.add("Authorized Revision", doc.getBuiltInDocumentProperties().getRevisionNumber());
properties.add("Authorized Amount", 123.45);

// Custom properties are automatically sorted in alphabetic order
Assert.assertEquals(properties.indexOf("Authorized Amount"), 1);
Assert.assertEquals(properties.getCount(), 5);

// Enumerate and print all custom properties
Iterator<DocumentProperty> enumerator = properties.iterator();
try {
    while (enumerator.hasNext()) {
        DocumentProperty property = enumerator.next();
        System.out.println(MessageFormat.format("Name: \"{0}\", Type: \"{1}\", Value: \"{2}\"", property.getName(), property.getType(), property.getValue()));
    }
} finally {
    if (enumerator != null) enumerator.remove();
}

// We can view/edit custom properties by opening the document and looking in File > Properties > Advanced Properties > Custom
doc.save(getArtifactsDir() + "Properties.DocumentPropertyCollection.docx");

// We can remove elements from the property collection by index or by name
properties.removeAt(1);
Assert.assertFalse(properties.contains("Authorized Amount"));
Assert.assertEquals(properties.getCount(), 4);

properties.remove("Authorized Revision");
Assert.assertFalse(properties.contains("Authorized Revision"));
Assert.assertEquals(properties.getCount(), 3);

// We can also empty the entire custom property collection at once
properties.clear();
Assert.assertEquals(properties.getCount(), 0);

contains

→ inherited from DocumentPropertyCollection
public boolean contains(java.lang.String name)
Returns true if a property with the specified name exists in the collection.
Parameters:
name - The case-insensitive name of the property.
Returns:
True if the property exists in the collection; false otherwise.

Example:

Shows how to add custom properties to a document.
Document doc = new Document();
CustomDocumentProperties properties = doc.getCustomDocumentProperties();

// The custom property collection will be empty by default
Assert.assertEquals(0, properties.getCount());

// We can populate it with key/value pairs with a variety of value types
properties.add("Authorized", true);
properties.add("Authorized By", "John Doe");
properties.add("Authorized Date", new Date());
properties.add("Authorized Revision", doc.getBuiltInDocumentProperties().getRevisionNumber());
properties.add("Authorized Amount", 123.45);

// Custom properties are automatically sorted in alphabetic order
Assert.assertEquals(properties.indexOf("Authorized Amount"), 1);
Assert.assertEquals(properties.getCount(), 5);

// Enumerate and print all custom properties
Iterator<DocumentProperty> enumerator = properties.iterator();
try {
    while (enumerator.hasNext()) {
        DocumentProperty property = enumerator.next();
        System.out.println(MessageFormat.format("Name: \"{0}\", Type: \"{1}\", Value: \"{2}\"", property.getName(), property.getType(), property.getValue()));
    }
} finally {
    if (enumerator != null) enumerator.remove();
}

// We can view/edit custom properties by opening the document and looking in File > Properties > Advanced Properties > Custom
doc.save(getArtifactsDir() + "Properties.DocumentPropertyCollection.docx");

// We can remove elements from the property collection by index or by name
properties.removeAt(1);
Assert.assertFalse(properties.contains("Authorized Amount"));
Assert.assertEquals(properties.getCount(), 4);

properties.remove("Authorized Revision");
Assert.assertFalse(properties.contains("Authorized Revision"));
Assert.assertEquals(properties.getCount(), 3);

// We can also empty the entire custom property collection at once
properties.clear();
Assert.assertEquals(properties.getCount(), 0);

indexOf

→ inherited from DocumentPropertyCollection
public int indexOf(java.lang.String name)
Gets the index of a property by name.

Note: In Java this method is slow because iterates over all nodes.

Parameters:
name - The case-insensitive name of the property.
Returns:
The zero based index. Negative value if not found.

Example:

Shows how to add custom properties to a document.
Document doc = new Document();
CustomDocumentProperties properties = doc.getCustomDocumentProperties();

// The custom property collection will be empty by default
Assert.assertEquals(0, properties.getCount());

// We can populate it with key/value pairs with a variety of value types
properties.add("Authorized", true);
properties.add("Authorized By", "John Doe");
properties.add("Authorized Date", new Date());
properties.add("Authorized Revision", doc.getBuiltInDocumentProperties().getRevisionNumber());
properties.add("Authorized Amount", 123.45);

// Custom properties are automatically sorted in alphabetic order
Assert.assertEquals(properties.indexOf("Authorized Amount"), 1);
Assert.assertEquals(properties.getCount(), 5);

// Enumerate and print all custom properties
Iterator<DocumentProperty> enumerator = properties.iterator();
try {
    while (enumerator.hasNext()) {
        DocumentProperty property = enumerator.next();
        System.out.println(MessageFormat.format("Name: \"{0}\", Type: \"{1}\", Value: \"{2}\"", property.getName(), property.getType(), property.getValue()));
    }
} finally {
    if (enumerator != null) enumerator.remove();
}

// We can view/edit custom properties by opening the document and looking in File > Properties > Advanced Properties > Custom
doc.save(getArtifactsDir() + "Properties.DocumentPropertyCollection.docx");

// We can remove elements from the property collection by index or by name
properties.removeAt(1);
Assert.assertFalse(properties.contains("Authorized Amount"));
Assert.assertEquals(properties.getCount(), 4);

properties.remove("Authorized Revision");
Assert.assertFalse(properties.contains("Authorized Revision"));
Assert.assertEquals(properties.getCount(), 3);

// We can also empty the entire custom property collection at once
properties.clear();
Assert.assertEquals(properties.getCount(), 0);

iterator

→ inherited from DocumentPropertyCollection
public java.util.Iterator<DocumentPropertyiterator()
Returns an iterator object that can be used to iterate over all items in the collection.

Example:

Shows how to add custom properties to a document.
Document doc = new Document();
CustomDocumentProperties properties = doc.getCustomDocumentProperties();

// The custom property collection will be empty by default
Assert.assertEquals(0, properties.getCount());

// We can populate it with key/value pairs with a variety of value types
properties.add("Authorized", true);
properties.add("Authorized By", "John Doe");
properties.add("Authorized Date", new Date());
properties.add("Authorized Revision", doc.getBuiltInDocumentProperties().getRevisionNumber());
properties.add("Authorized Amount", 123.45);

// Custom properties are automatically sorted in alphabetic order
Assert.assertEquals(properties.indexOf("Authorized Amount"), 1);
Assert.assertEquals(properties.getCount(), 5);

// Enumerate and print all custom properties
Iterator<DocumentProperty> enumerator = properties.iterator();
try {
    while (enumerator.hasNext()) {
        DocumentProperty property = enumerator.next();
        System.out.println(MessageFormat.format("Name: \"{0}\", Type: \"{1}\", Value: \"{2}\"", property.getName(), property.getType(), property.getValue()));
    }
} finally {
    if (enumerator != null) enumerator.remove();
}

// We can view/edit custom properties by opening the document and looking in File > Properties > Advanced Properties > Custom
doc.save(getArtifactsDir() + "Properties.DocumentPropertyCollection.docx");

// We can remove elements from the property collection by index or by name
properties.removeAt(1);
Assert.assertFalse(properties.contains("Authorized Amount"));
Assert.assertEquals(properties.getCount(), 4);

properties.remove("Authorized Revision");
Assert.assertFalse(properties.contains("Authorized Revision"));
Assert.assertEquals(properties.getCount(), 3);

// We can also empty the entire custom property collection at once
properties.clear();
Assert.assertEquals(properties.getCount(), 0);

remove

→ inherited from DocumentPropertyCollection
public void remove(java.lang.String name)
Removes a property with the specified name from the collection.
Parameters:
name - The case-insensitive name of the property.

Example:

Shows how to add custom properties to a document.
Document doc = new Document();
CustomDocumentProperties properties = doc.getCustomDocumentProperties();

// The custom property collection will be empty by default
Assert.assertEquals(0, properties.getCount());

// We can populate it with key/value pairs with a variety of value types
properties.add("Authorized", true);
properties.add("Authorized By", "John Doe");
properties.add("Authorized Date", new Date());
properties.add("Authorized Revision", doc.getBuiltInDocumentProperties().getRevisionNumber());
properties.add("Authorized Amount", 123.45);

// Custom properties are automatically sorted in alphabetic order
Assert.assertEquals(properties.indexOf("Authorized Amount"), 1);
Assert.assertEquals(properties.getCount(), 5);

// Enumerate and print all custom properties
Iterator<DocumentProperty> enumerator = properties.iterator();
try {
    while (enumerator.hasNext()) {
        DocumentProperty property = enumerator.next();
        System.out.println(MessageFormat.format("Name: \"{0}\", Type: \"{1}\", Value: \"{2}\"", property.getName(), property.getType(), property.getValue()));
    }
} finally {
    if (enumerator != null) enumerator.remove();
}

// We can view/edit custom properties by opening the document and looking in File > Properties > Advanced Properties > Custom
doc.save(getArtifactsDir() + "Properties.DocumentPropertyCollection.docx");

// We can remove elements from the property collection by index or by name
properties.removeAt(1);
Assert.assertFalse(properties.contains("Authorized Amount"));
Assert.assertEquals(properties.getCount(), 4);

properties.remove("Authorized Revision");
Assert.assertFalse(properties.contains("Authorized Revision"));
Assert.assertEquals(properties.getCount(), 3);

// We can also empty the entire custom property collection at once
properties.clear();
Assert.assertEquals(properties.getCount(), 0);

removeAt

→ inherited from DocumentPropertyCollection
public void removeAt(int index)
Removes a property at the specified index.

Note: In Java this method is slow because iterates over all nodes.

Parameters:
index - The zero based index.

Example:

Shows how to add custom properties to a document.
Document doc = new Document();
CustomDocumentProperties properties = doc.getCustomDocumentProperties();

// The custom property collection will be empty by default
Assert.assertEquals(0, properties.getCount());

// We can populate it with key/value pairs with a variety of value types
properties.add("Authorized", true);
properties.add("Authorized By", "John Doe");
properties.add("Authorized Date", new Date());
properties.add("Authorized Revision", doc.getBuiltInDocumentProperties().getRevisionNumber());
properties.add("Authorized Amount", 123.45);

// Custom properties are automatically sorted in alphabetic order
Assert.assertEquals(properties.indexOf("Authorized Amount"), 1);
Assert.assertEquals(properties.getCount(), 5);

// Enumerate and print all custom properties
Iterator<DocumentProperty> enumerator = properties.iterator();
try {
    while (enumerator.hasNext()) {
        DocumentProperty property = enumerator.next();
        System.out.println(MessageFormat.format("Name: \"{0}\", Type: \"{1}\", Value: \"{2}\"", property.getName(), property.getType(), property.getValue()));
    }
} finally {
    if (enumerator != null) enumerator.remove();
}

// We can view/edit custom properties by opening the document and looking in File > Properties > Advanced Properties > Custom
doc.save(getArtifactsDir() + "Properties.DocumentPropertyCollection.docx");

// We can remove elements from the property collection by index or by name
properties.removeAt(1);
Assert.assertFalse(properties.contains("Authorized Amount"));
Assert.assertEquals(properties.getCount(), 4);

properties.remove("Authorized Revision");
Assert.assertFalse(properties.contains("Authorized Revision"));
Assert.assertEquals(properties.getCount(), 3);

// We can also empty the entire custom property collection at once
properties.clear();
Assert.assertEquals(properties.getCount(), 0);

See Also:
          Aspose.Words Documentation - the home page for the Aspose.Words Product Documentation.
          Aspose.Words Support Forum - our preferred method of support.