For details, you may visit following blog post:
Last active
January 12, 2021 18:05
-
-
Save GroupDocsGists/6114128ca015cbb1740cd8e05fd62fb3 to your computer and use it in GitHub Desktop.
Remove Specific Metadata Properties from Documents and Images
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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