Adding metadata

View as MarkdownMarkdown

Set up your AI agent

Give your coding agent live access to the GroupDocs documentation and API reference through the GroupDocs Docs MCP server — no install, no API key. Learn more

claude mcp add --transport http groupdocs-docs https://docs.groupdocs.com/mcp

Also process documents locally

The GroupDocs.Metadata MCP server lets your agent work with files on your machine; they are never uploaded. It needs the .NET 10 SDK or Docker.

claude mcp add groupdocs-metadata -- dnx GroupDocs.Metadata.Mcp --yes
Folders, licensing and more →

Adding metadata properties is the most sophisticated feature of the GroupDocs.Metadata search engine. When you call the addProperties method it examines all available metadata packages and tries to pick up a known property that would satisfy the specified predicate. Note that the property will be added to metadata packages that fit the following criteria: 

  1. Only existing metadata packages will be affected. No new packages are added during this operation
  2. There should be a known metadata property in the package structure that fits the search condition but is actually missing in the package. All properties supported by a certain package are usually defined in the specification of a particular metadata standard

advanced_usage.AddingMetadata

File folder = new File(Constants.InputPath);
for (File file : folder.listFiles()) {
    try (Metadata metadata = new Metadata(file.getAbsolutePath())) {
        if (metadata.getFileFormat() != FileFormat.Unknown && !metadata.getDocumentInfo().isEncrypted()) {
            System.out.println();
            System.out.println(file.getName());

            // Add a property containing the file last printing date if it's missing
            // Note that the property will be added to metadata packages that satisfy the following criteria:
            // 1) Only existing metadata packages will be affected. No new packages are added during this operation
            // 2) There should be a known metadata property in the package structure that fits the search condition but is actually missing in the package.
            // All properties supported by a certain package are usually defined in the specification of a particular metadata standard
            int affected = metadata.addProperties(new ContainsTagSpecification(Tags.getTime().getPrinted()), new PropertyValue(new Date()));

            System.out.println(String.format("Affected properties: %s", affected));

            metadata.save(Constants.OutputPath + "output." + FilenameUtils.getExtension(file.getName()));
        }
    }
}

More resources

GitHub examples

You may easily run the code above and see the feature in action in our GitHub examples:

Free online document metadata management App

Along with full featured Java library we provide simple, but powerful free Apps.

You are welcome to view and edit metadata of PDF, DOC, DOCX, PPT, PPTX, XLS, XLSX, emails, images and more with our free online Free Online Document Metadata Viewing and Editing App.