Set document metadata on save

GroupDocs.Comparison provides an ability to select metadata source when saving resultant file. Files have metadata information – author, organization, etc.  

Possible metadata sources are:

  • Source file metadata;
  • Target file metadata;
  • User-defined metadata.

The following are the steps to set resultant file metadata:

The following code demonstrates how to set resultant file metadata.

Set metadata from source file

Comparer comparer = new Comparer("C:\\source.pdf");
try {
    comparer.add("C:\\target.pdf");
    final SaveOptions saveOptions = new SaveOptions();
    saveOptions.setCloneMetadataType(MetadataType.Source);
    comparer.compare("C:\\result.pdf", saveOptions);
} finally {
    comparer.dispose();
}

Set metadata from target file

Comparer comparer = new Comparer("C:\\source.pdf");
try {
    comparer.add("C:\\target.pdf");
    final SaveOptions saveOptions = new SaveOptions();
    saveOptions.setCloneMetadataType(MetadataType.Target);
    comparer.compare("C:\\result.pdf", saveOptions);
} finally {
    comparer.dispose();
}

Set user-defined metadata 

Comparer comparer = new Comparer("C:\\source.pdf");
try {
    comparer.add("C:\\target.pdf");
    final FileAuthorMetadata fileAuthorMetadata = new FileAuthorMetadata();
    fileAuthorMetadata.setAuthor("Tom");
    fileAuthorMetadata.setCompany("GroupDocs");
    fileAuthorMetadata.setLastSaveBy("Jack");
    final SaveOptions saveOptions = new SaveOptions();
    saveOptions.setCloneMetadataType(MetadataType.FileAuthor);
    saveOptions.setFileAuthorMetadata(fileAuthorMetadata);
    comparer.compare("C:\\result.pdf", saveOptions);
} finally {
    comparer.dispose();
}

More resources

GitHub Examples

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

Free Online App

Along with full-featured Java library we provide simple, but powerful free Apps. You are welcome to compare your DOC or DOCX, XLS or XLSX, PPT or PPTX, PDF, EML, EMLX, MSGand other documents with free to use online GroupDocs Comparison App.