GroupDocs.Metadata Cloud SDK for Java enables Java developers to programmatically read and modify PDF document properties. In this guide you will learn how to edit PDF metadata in Java, update standard fields like Title and Author, and add custom key‑value pairs. The SDK provides a simple API to load a PDF, change its metadata, and save the file back to storage. Follow the step‑by‑step instructions to integrate metadata editing into your Java applications.

Prerequisites and Setup

To work with PDF metadata you need Java 8 or higher and Maven installed on your development machine. Download the latest version from this page.

Add the SDK to your Maven project:

<dependency>
    <groupId>com.groupdocs</groupId>
    <artifactId>groupdocs-metadata-cloud</artifactId>
    <version>23.9</version>
</dependency>

Or install it via the command line:

mvn install com.groupdocs:groupdocs-metadata-cloud

Create a configuration file (or set environment variables) with your client ID and client secret obtained from the GroupDocs Cloud dashboard. No license code is required for this example; a temporary license can be requested from the license page.

Understanding PDF Metadata

PDF files contain a set of standard properties (Title, Author, Subject, Keywords) and allow custom key‑value pairs. These properties are stored in the document’s metadata dictionary and can be read or modified without altering the visual content of the file.

Key Features of GroupDocs.Metadata Cloud SDK for Java

  • Read existing metadata from PDF, DOCX, XLSX, and many other formats.
  • Update standard properties such as Title, Author, Creator, and Producer.
  • Add, edit, or remove custom properties using a simple map interface.
  • Save changes back to the original file or to a new output location.

Modifying Standard PDF Document Properties

The SDK exposes the MetadataInfo class which provides getters and setters for all standard fields. You can also access the CustomProperties collection to work with user‑defined entries.

Adding Custom Metadata Fields

Custom metadata is stored as a dictionary of string keys and values. The SDK automatically serializes these entries when the document is saved, making them available to any PDF reader that supports custom metadata.

Steps to Edit PDF Metadata in Java

  1. Initialize the API client: Create a Configuration object with your credentials and instantiate the MetadataApi.
  2. Upload the source PDF: Use the StorageApi to place the file in your GroupDocs Cloud storage.
  3. Load the PDF metadata: Call metadataApi.getMetadataInfo to retrieve a MetadataInfo object.
  4. Update fields: Set standard properties (e.g., setTitle, setAuthor) and add custom entries via getCustomProperties().put("MyKey", "MyValue").
  5. Save the changes: Invoke metadataApi.updateMetadataInfo to write the modified metadata back to the file.

For more details on the classes used, refer to the API reference.

Edit PDF Metadata in Java - Complete Code Example

The following example demonstrates a full workflow: authentication, file upload, metadata modification, and saving the updated PDF.

Note: This code example demonstrates the core functionality. Before using it in your project, make sure to update the file paths (sample.pdf, C:/files/sample.pdf) 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.

Edit PDF Metadata via REST API using cURL

If you prefer not to use the Java library, the same operation can be performed through the GroupDocs Metadata Cloud REST API.

  1. Obtain an access token

    curl -X POST "https://api.groupdocs.cloud/v2.0/oauth/token" \
         -H "Content-Type: application/json" \
         -d '{"client_id":"YOUR_CLIENT_ID","client_secret":"YOUR_CLIENT_SECRET"}'
    
  2. Upload the PDF file

    curl -X PUT "https://api.groupdocs.cloud/v2.0/storage/file/sample.pdf" \
         -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
         -H "Content-Type: application/octet-stream" \
         --data-binary "@C:/files/sample.pdf"
    
  3. Update metadata

    curl -X POST "https://api.groupdocs.cloud/v2.0/metadata/pdf/sample.pdf/metadata" \
         -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
         -H "Content-Type: application/json" \
         -d '{
               "title":"New Document Title",
               "author":"John Doe",
               "subject":"Updated Subject",
               "customProperties":{"Project":"Alpha","ReviewedBy":"Jane Smith"}
             }'
    
  4. Download the updated PDF

    curl -X GET "https://api.groupdocs.cloud/v2.0/storage/file/sample.pdf" \
         -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
         -o "C:/files/updated_sample.pdf"
    

These commands let you integrate PDF metadata editing into scripts, CI/CD pipelines, or any environment where installing the Java library is not practical. For a full list of endpoints, see the API documentation.

Conclusion

You now have a complete understanding of how to edit PDF metadata in Java using GroupDocs.Metadata Cloud SDK for Java. The guide covered reading existing metadata, modifying standard fields such as Title and Author, adding custom key‑value pairs, and persisting the changes. The SDK runs on your local machine or server and requires a valid license; you can start with a temporary license from the license page and upgrade to a full commercial license for production use. Incorporate these techniques to keep your PDF documents well‑organized and searchable.

FAQs

How can I edit PDF metadata in Java using GroupDocs.Metadata Cloud SDK?
Use the SDK to load a PDF, modify its MetadataInfo properties, and save the file. See the GroupDocs.Metadata Cloud SDK for Java documentation for details.

Can I add custom key-value pairs to a PDF’s metadata?
Yes, the SDK allows adding custom entries via the setCustomProperties method. Refer to the API reference for examples.

Is a temporary license sufficient for development?
A temporary license from the license page lets you test the SDK. For production, purchase a full license.

Where can I find more examples for PDF metadata manipulation?
The official documentation and the forums contain additional samples and community support.

Read More