add_properties method

add_properties

Adds known metadata properties satisfying the specified predicate. The operation is recursive so it affects all nested packages as well.

Learn more:

def add_properties(self, predicate, value):
    ...
Parameter Type Description
predicate Func[MetadataProperty, bool] Callable[[MetadataProperty], bool] – A function to test each metadata property for a condition.
value PropertyValue PropertyValue – A value for the picked properties.

Returns: int – The number of affected properties.

Example

from datetime import datetime

from groupdocs.metadata import Metadata
from groupdocs.metadata.common import PropertyValue
from groupdocs.metadata.tagging import Tags

def adding_metadata():
    with Metadata("input.docx") as metadata:
        # Add the "last printed" date wherever it is a known but missing property
        property_value = PropertyValue(datetime.now())
        affected = metadata.add_properties(
            lambda p: Tags.time.printed in list(p.tags), property_value
        )
        print(f"Affected properties: {affected}")
        metadata.save("output.docx")

See Also