Yet another news for Cloud Developers! GroupDocs has launched the Document Metadata Manipulation Cloud API. This enriches the document metadata management solution of GroupDocs. The solution is already serving .NET and Java developers as On-Premise APIs for developers, and as Free Online Document Metadata Editor App for any kind of user to view and edit metadata of documents.

Metadata Manipulation Cloud API

GroupDocs.Metadata for Cloud

GroupDocs.Metadata Cloud API along with SDKs that allow developers to manipulate (add, remove, update, extract, and view) metadata of more than 50 file formats.

GroupDocs.Metadata allows to access and deal with metadata of files in different ways like:

  • Possible Tag Name
  • Property Name
  • Property Value
  • Match Exact Phrase
  • Match Regex
  • Whole Metadata Tree
  • Tag

To get a much better idea about the features and the product, you can always visit the developer guide in the documentation section.

Supported Document Formats

You can perform operations on documents that can be any of the word processing documents, spreadsheets, presentations, audio and video files, images, PDF, eBooks, drawings, and many more. Below listed are the file formats that are currently supported by the GroupDocs API and will hopefully fulfill your requirements. You can visit the documentation any time to know about all the supported document formats or any kind of guidance.

Metadata - SDKs and Samples

Along with the metadata editing REST API for Cloud, GroupDocs also provides open-source SDKs, therefore, these can be self-customized according to the requirements. Developers can use cURL to interact with GroupDocs.Metadata Cloud API and can also use the relevant SDK(s) to speed up the development. This helps developers to stop worrying about low-level details of making a request and handling the responses. Below-mentioned SDKs along with the code examples are available on GitHub:

In this blog. I am using the Java code to show how to play with the metadata properties of documents. Further, I will show only one of the ways to extract, add, remove, and modify the metadata. You can also see the C# examples and other ways in detail from the documentation and relevant GitHub repositories.

Extract Metadata from Files in Java or .NET

The API allows you to extract the metadata of your documents with different options that include extracting:

  • The whole metadata properties tree
  • By specified tag, name or value

For your help, the running examples are available on GitHub.
I have uploaded an example of groupdocs.app that shows, how much you can extract and create your own metadata applications with C# and Java.

Extract Whole Metadata Properties Tree in Java

After setting the connection with your cloud storage, you can extract the whole tree of metadata properties with the help of the below-mentioned few lines of code. Here, I am extracting the properties tree of an excel spreadsheet using Java SDK for Cloud. You can easily achieve this using any of the other available SDKs.

// Set File Path
FileInfo fileInfo = new FileInfo();
fileInfo.setFilePath("documents"+ File.separator +"input.xlsx");
// Set Options to extract the metadata from any file.
ExtractOptions options = new ExtractOptions();
options.setFileInfo(fileInfo);
// Send a Request with options to extract metadata and received the response.
ExtractRequest request = new ExtractRequest(options);
ExtractResult response = apiInstance.extract(request);

Printing the Whole Metadata Tree in Java

// That's it. You have received the whole Metadata Tree. Now you can use it the way you like.
for (MetadataProperty entry : response.getMetadataTree().getInnerPackages().get(0).getPackageProperties()){
	System.out.println("\\n" + entry.getName() + ": " + entry.getValue());
	if (entry.getTags() == null)
		continue;
	// Print Tags
	for (Tag tagItem : entry.getTags()) {
		System.out.println("=== Tag for Property ===");
		System.out.println("Name :" + tagItem.getName());
		System.out.println("Category: " + tagItem.getCategory());
	}
}

Output

FileFormat: 2
=== Tag for Property ===
Name :FileFormat
Category: Content

MimeType: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
=== Tag for Property ===
Name :FileFormat
Category: Content
 
SpreadsheetFileFormat: 3
=== Tag for Property ===
Name :FileFormat
Category: Content

All the other different ways of metadata extraction can be seen at any of the following resources:

Add Metadata using Java or .NET

GroupDocs Metadata REST API allows you to add metadata to your documents with the following features:

  • Metadata properties may contain different types of values like String, DateTime, Integer, Double, Boolean
  • Properties can be added in following different ways:
    • Add Metadata Property by Name:
      • Part of Name
      • Exact Phrase
      • Regex Match
    • Add Metadata Property by Tag:
      • Exact Tag
      • Possible Tag Name

Add Metadata Property by Exact Tag in Java

Below, you can see the source code example for adding the metadata property by an exact tag:

AddOptions options = new AddOptions();
ArrayList<AddProperty> properties = new ArrayList<AddProperty>();
AddProperty property = new AddProperty();
SearchCriteria searchCriteria = new SearchCriteria();
TagOptions tagOptions = new TagOptions();
// Set Tag name and category
Tag tag = new Tag();
tag.setName("Printed");
tag.setCategory("Time");
// Set Tag
tagOptions.setExactTag(tag);
searchCriteria.setTagOptions(tagOptions);
//Set Date for Value
Date date = new Date();
DateFormat dateFormat = new SimpleDateFormat("MM-dd-yyyy hh:mm:ss");
// Setting the Add Property
property.setSearchCriteria(searchCriteria);
property.setValue(dateFormat.format(date));
property.setType("datetime");
properties.add(property);
// Set Properties of AddOptions
options.setProperties(properties);
// Select the document to add metadata property
FileInfo fileInfo = new FileInfo();
fileInfo.setFilePath("documents/input.docx");
options.setFileInfo(fileInfo);
// Sending the request and fetch response after adding the metadata property
AddRequest request = new AddRequest(options);
AddResult response = apiInstance.add(request);
// Printing the Changes Count and Path of changed file.
System.out.println("Count of changes: " + response.getAddedCount());
System.out.println("Resultant file path: " + response.getPath());

Output: After adding metadata by tag

Count of changes: 1
Resultant file path: metadata/add\_metadata/documents/input\_docx/input.docx

All the other different ways of adding metadata can be seen at any of the following resources:

Remove Metadata using Java or .NET

Almost with similar options to add the metadata properties, you can also remove the metadata properties from your documents.

  • Metadata properties may contain different types of values like String, DateTime, Integer, Double, Boolean.
  • Metadata properties can be deleted/removed in following different ways:
    • Remove Metadata Property by Name:
      • Part of Name
      • Exact Phrase
      • Matching Regular Expression
    • Remove Metadata Property by Tag:
      • Exact Tag
      • Possible Tag Name

Remove Metadata using Regular Expression (Regex) in Java

Below, you can see the source code example for removing the metadata properties that match the provided regular expression:

// Name Options
NameOptions nameOptions = new NameOptions();
nameOptions.setValue("^\[N\]ame\[A-Z\].\*");
// Match Options
MatchOptions matchOptions = new MatchOptions();
matchOptions.setIsRegex(true);
nameOptions.setMatchOptions(matchOptions);
// Remove Metadata Options and Search Criteria
RemoveOptions options = new RemoveOptions();
SearchCriteria searchCriteria = new SearchCriteria();
// Search Criteria
searchCriteria.setNameOptions(nameOptions);
options.setSearchCriteria(searchCriteria);
// Set fileInfo for the source document
FileInfo fileInfo = new FileInfo();
fileInfo.setFilePath("documents/input.docx");
options.setFileInfo(fileInfo);
// Send request to remove and receive the response
RemoveRequest request = new RemoveRequest(options);
RemoveResult response = apiInstance.remove(request);
// In response, you can get the path of the updated document with the removed properies.
System.out.println("Count of changes: " + response.getRemovedCount());
System.out.println("Resultant file path: " + response.getPath());

Output: After removing metadata by regex

Count of changes: 1
Resultant file path: metadata/remove\_metadata/documents/input\_docx/input.docx 

All the other different ways of removing the metadata can be seen at any of the following resources:

Update Metadata using Java or .NET

Along with adding, removing, and extracting the metadata, the REST API allows updating the existing metadata properties in different ways. Below I will show how you can update the metadata property of any document using Java code by providing the property possible tag name. I have used an excel spreadsheet to update its creator metadata tag. You can achieve the same in C# using .NET API.

Update Metadata by Possible Tag Name using Java

SetOptions options = new SetOptions();
ArrayList<SetProperty> properties = new ArrayList<SetProperty>();
SetProperty property = new SetProperty();
SearchCriteria searchCriteria = new SearchCriteria();
// Set Tag Options and Possible Tag Name
TagOptions tagOptions = new TagOptions();
tagOptions.setPossibleName("creator");
searchCriteria.setTagOptions(tagOptions);
//Set the new Value and Type and then add the property
property.setSearchCriteria(searchCriteria);
property.setNewValue("GroupDocs");
property.setType("string");
properties.add(property);
options.setProperties(properties);
// Select the file to update its metadata properties
FileInfo fileInfo = new FileInfo();
fileInfo.setFilePath("documents/input.xlsx");
options.setFileInfo(fileInfo);
// Send Request and catch the Response
SetRequest request = new SetRequest(options);
SetResult response = apiInstance.set(request);
// Print the Response Fields
System.out.println("Changes count: " + response.getSetCount());
System.out.println("Resultant file path: " + response.getPath());

Output: After modifying metadata by possible tag name

 Count of changes: 1
 Resultant file path: metadata/set\_metadata/documents/input\_xlsx/input.xlsx 

You can download the updated document from the path returned in the response. Further, you can update the existing properties in similar ways like adding and removing metadata. Example and explanations can be seen on the following resources of GroupDocs.Metadata Cloud API.

Let’s Talk

This summarizes the overview of GroupDocs.Metadata Cloud API. Now you can build your own application using the above-highlighted features. We will be delighted if you contact us on the forum to discuss, solving a problem, or share your feedback. Thanks.

Resources