Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Remove Specific Metadata Properties from Documents and Images
// Remove the metadata properties from documents and images that satisfies the customized filter using C#
using (Metadata metadata = new Metadata("filePath/document.docx"))
{
// Remove all the properties that:
// contains the name of the document author OR
// it refers to the last editor OR
// the property value is a string AND equal to the given string "GroupDocs"
var affected = metadata.RemoveProperties(
p => p.Tags.Contains(Tags.Person.Creator) ||
p.Tags.Contains(Tags.Person.Editor) ||
p.Value.Type == MetadataPropertyType.String && p.Value.ToString().Contains("GroupDocs"));
Console.WriteLine("Properties removed: {0}", affected);
metadata.Save("outputPath/document.docx");
}
// Remove the metadata properties from documents and images that satisfies the customized filter using Java
public class RemoveMetadataProperties {
public static void removeMetadataProperties() {
Metadata metadata = new Metadata("filePath/document.docx");
/*
* Remove all the properties that:
* contains the name of the document author OR
* it refers to the last editor OR
* the property value is a string AND equal to the given string "GroupDocs"
*/
int affected = metadata.removeProperties(new ContainsTagSpecification(Tags.getPerson().getCreator())
.or(new ContainsTagSpecification(Tags.getPerson().getEditor()))
.or(new OfTypeSpecification(MetadataPropertyType.String)
.and(new RemoveMetadataProperties().new WithValueSpecification("GroupDocs"))));
System.out.println(String.format("Properties removed: %s", affected));
metadata.save("outputPath/document.docx");
}
// Create personalized specifications to filter metadata properties
public class WithValueSpecification extends Specification {
public WithValueSpecification(Object value) {
setValue(value);
}
public final Object getValue() {
return auto_Value;
}
private void setValue(Object value) {
auto_Value = value;
}
private Object auto_Value;
public boolean isSatisfiedBy(MetadataProperty candidate) {
return candidate.getValue().getRawValue().equals(getValue());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment