Set document metadata on save

A document can contain some metadata information, such as author, organization, etc. GroupDocs.Comparison allows you to select metadata sources when saving the output document.

Possible metadata sources are as follows:

  • Source document metadata
  • Target document metadata
  • User-defined metadata

To set output document metadata, follow these steps:

  1. Instantiate the Comparer object. Specify the source document path or stream.
  2. Call the add() method. Specify the target document path or stream.
  3. Instantiate the SaveOptions object. Call the setCloneMetadataType() method to set the appropriate MetadataType variant.
  4. Call the compare() method. Specify the SaveOptions object as a parameter.

The following code snippets show how to set output document metadata:

Set metadata from the source file

const comparer = new groupdocs.comparison.Comparer(sourceFile);
comparer.add(targetFile);
const saveOptions = new groupdocs.comparison.SaveOptions();
saveOptions.setCloneMetadataType(groupdocs.comparison.MetadataType.SOURCE);
const resultPath = comparer.compare(outputFile, saveOptions);

Set metadata from the target file

const comparer = new groupdocs.comparison.Comparer(sourceFile);
comparer.add(targetFile);
const saveOptions = new groupdocs.comparison.SaveOptions();
saveOptions.setCloneMetadataType(groupdocs.comparison.MetadataType.TARGET);
const resultPath = comparer.compare(outputFile, saveOptions);

Set user-defined metadata 

const comparer = new groupdocs.comparison.Comparer(sourceFile);
comparer.add(targetFile);
const fileAuthorMetadata = new groupdocs.comparison.FileAuthorMetadata();
fileAuthorMetadata.setAuthor("Tom");
fileAuthorMetadata.setCompany("GroupDocs");
fileAuthorMetadata.setLastSaveBy("Jack");
const saveOptions = new groupdocs.comparison.SaveOptions();
saveOptions.setCloneMetadataType(groupdocs.comparison.MetadataType.FILEAUTHOR);
saveOptions.setFileAuthorMetadata(fileAuthorMetadata);
const resultPath = comparer.compare(outputFile, saveOptions);