Working with document properties is essential for organized content management. GroupDocs.Metadata Cloud SDK for Java enables Java developers to edit Word document metadata programmatically, offering a simple API for reading and updating core and custom fields. This guide shows how to edit Word document Metadata in Java, covering setup, code implementation, bulk processing tips, and common troubleshooting.
Edit Word Document Metadata - Prerequisites and Setup
To start using the library you need Java 8 or higher and Maven installed on your development machine.
Installation
Add the SDK to your project with the Maven coordinate provided by GroupDocs:
<dependency>
<groupId>com.groupdocs</groupId>
<artifactId>groupdocs-metadata-cloud</artifactId>
<version>latest</version>
</dependency>
Alternatively you can run the command line installer:
mvn install com.groupdocs:groupdocs-metadata-cloud
Download the latest binaries from this page. After adding the dependency, configure your client with your client ID and client secret (available in your GroupDocs account).
import com.groupdocs.metadata.cloud.ApiClient;
import com.groupdocs.metadata.cloud.Configuration;
Configuration config = new Configuration();
config.setClientId("YOUR_CLIENT_ID");
config.setClientSecret("YOUR_CLIENT_SECRET");
ApiClient apiClient = new ApiClient(config);
For detailed configuration options see the official documentation.
Edit Word Document Metadata in Java
The SDK supports reading and writing core properties (Title, Author, Subject, etc.) as well as custom properties defined by the user. It follows the Office Open XML standard, ensuring compatibility with Microsoft Word and other editors.
Key Features of GroupDocs.Metadata Cloud SDK for Java
- Core Property Management - Access and modify built‑in fields such as Title, Creator, and Keywords.
- Custom Property Support - Add, update, or delete user‑defined metadata.
- Category Handling - Manage document categories programmatically, a useful feature for content classification.
- Bulk Operations - Process many files in a single request to improve performance.
- Error Reporting - Detailed exceptions help pinpoint missing properties or permission issues.
Configuring Metadata Fields with GroupDocs.Metadata Cloud SDK
Use the DocumentInfo class to retrieve and set property values. The API reference provides full details for each method: DocumentInfo Class.
import com.groupdocs.metadata.cloud.model.requests.*;
import com.groupdocs.metadata.cloud.model.*;
DocumentInfoRequest request = new DocumentInfoRequest("sample.docx");
DocumentInfoResponse response = apiClient.getDocumentInfo(request);
DocumentInfo info = response.getInfo();
// Update core properties
info.setTitle("Quarterly Report");
info.setAuthor("John Doe");
// Add a custom property
info.getCustomProperties().add(new CustomProperty("ProjectCode", "PRJ-2026"));
Handling Custom Properties and Categories
Custom properties are stored as key‑value pairs. You can also assign categories to help with document organization.
// Add a new category
info.getCategories().add("Finance");
// Update an existing custom property
info.getCustomProperties().stream()
.filter(p -> p.getName().equals("ProjectCode"))
.findFirst()
.ifPresent(p -> p.setValue("PRJ-2027"));
Performance Optimization for Bulk Metadata Updates
When updating metadata for many documents, reuse the same ApiClient instance and leverage the bulk endpoint.
BulkUpdateRequest bulkRequest = new BulkUpdateRequest();
bulkRequest.addFile("doc1.docx", info1);
bulkRequest.addFile("doc2.docx", info2);
// ... add more files
BulkUpdateResponse bulkResponse = apiClient.bulkUpdateMetadata(bulkRequest);
Processing files in parallel threads can further reduce total execution time.
Troubleshooting Common Metadata Editing Issues
- Missing Property Exception - Verify that the property name is spelled correctly and exists in the document.
- Permission Errors - Ensure the API client has write access to the storage location.
- Unsupported Format - The SDK works with DOCX; older DOC files must be converted first.
Steps to Edit Word Document Metadata in Java
- Initialize the API client - Provide your client credentials and create an
ApiClientinstance. - Load the Word document - Use
DocumentInfoRequestto fetch existing metadata. - Modify core and custom fields - Set values on the
DocumentInfoobject as shown in the examples. - Save changes - Call the
UpdateDocumentMetadataendpoint to write the updated metadata back to the file. - Verify the update - Retrieve the document info again to confirm that changes were applied.
For more details on each class, refer to the API reference.
Edit Word Document Metadata in Java - Complete Code Example
The following example demonstrates a complete workflow that reads a DOCX file, updates several metadata fields, and saves the result.
Note: This code example demonstrates the core functionality. Before using it in your project, make sure to update the file paths (
sample.docx) to match your actual file locations, verify that all required dependencies are properly installed, and test thoroughly in your development environment. If you encounter any issues, please refer to the official documentation or reach out to the support team for assistance.
Managing Document Metadata via REST API using cURL
The same operations can be performed through the cloud REST API. Below are the essential cURL commands.
1. Authenticate and obtain an access token
curl -X POST "https://api.groupdocs.cloud/v1.0/auth/login" \
-H "Content-Type: application/json" \
-d '{"client_id":"YOUR_CLIENT_ID","client_secret":"YOUR_CLIENT_SECRET"}'
2. Upload the source Word file
curl -X POST "https://api.groupdocs.cloud/v1.0/storage/upload" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-F "file=@/path/to/sample.docx"
3. Update metadata (core and custom properties)
{
"title": "Annual Financial Summary",
"author": "Finance Team",
"customProperties": [
{ "name": "Department", "value": "Finance" }
],
"categories": ["Financial Reports"]
}
curl -X PUT "https://api.groupdocs.cloud/v1.0/metadata/docx/sample.docx" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d @metadata_update.json
4. Download the updated file
curl -X GET "https://api.groupdocs.cloud/v1.0/storage/download/sample.docx" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-o updated_sample.docx
For the full API specification see the API reference.
Conclusion
Editing Word document metadata programmatically in Java becomes straightforward with the GroupDocs.Metadata Cloud SDK for Java. You can modify core properties, add custom fields, and manage categories efficiently, even when processing large batches. Remember to acquire a proper license for production use; pricing details are available on the product page, and a temporary license can be obtained from the temporary license page. Integrate these practices into your content management or document processing pipelines to keep your files well‑organized and searchable.
FAQs
How do I update the document title without affecting other properties?
Use the setTitle method on the DocumentInfo object. The SDK updates only the specified field, leaving all other metadata untouched.
Can I remove a custom property that is no longer needed?
Yes, retrieve the CustomProperties collection, locate the property by name, and call the remove method. The change is persisted after calling updateDocumentMetadata.
Is there a way to batch edit metadata for dozens of Word files?
The SDK provides a bulk update endpoint that accepts multiple files in a single request. This reduces network overhead and speeds up processing.
Where can I find examples for handling metadata categories?
The official documentation includes code snippets for adding and removing categories, as well as best‑practice recommendations for large‑scale operations.
