Search Metadata Properties
You can easily search metadata and extract desired metadata properties from PDF, DOCX, PPTX, XLSX, images, audio, video and many other files of different types in your Java solution by using GroupDocs.Metadata Java API.
GroupDocs.Metadata for Java (which is the part of Conholdate.Total for Java) supports many file formats. See full list at supported file formats article.
Use tags to find most common metadata properties
To make manipulating metadata easier we attach specific tags to the most commonly used metadata properties extracted from a file. Some metadata standards can have quite a complex structure. Moreover, in most cases, one image, video or document contains more than one metadata packages. Using tags you can search for desirable properties with a few lines of code without even knowing the exact format of the loaded file.
The code sample below demonstrates how to search for specific metadata properties using tags:
- Load a file to examine
- Make up a predicate checking that a specific tag is assigned to a property (alternatively you can use a combination of tags)
- Pass the predicate to the findProperties method
- Iterate through the found properties
// Constants.InputPptx is an absolute or relative path to your document. Ex: @"C:\Docs\source.pptx"
try (Metadata metadata = new Metadata(Constants.InputPptx)) {
// Fetch all the properties satisfying the predicate:
// property contains the name of the last document editor OR the date/time the document was last modified
IReadOnlyList<MetadataProperty> properties = metadata.findProperties(
new ContainsTagSpecification(Tags.getPerson().getEditor()).or(new ContainsTagSpecification(Tags.getTime().getModified())));
for (MetadataProperty property : properties) {
System.out.println(String.format("Property name: %s, Property value: %s", property.getName(), property.getValue()));
}
}
As a result, we obtain all metadata properties containing the name of the person last edited the document and all properties that store the date/time the document was last edited.