Set document metadata on save
Leave feedback
On this page
Document can contain some metadata information, such as author, organization, etc. GroupDocs.Comparison allows you to select metadata source when saving 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:
- Instantiate the Comparer object. Specify the source document path or stream.
- Call the add() method. Specify the target document path or stream.
- Instantiate the SaveOptions object. Call the setCloneMetadataType() method to set the appropriate MetadataType variant.
- Call the compare() method. Specify the SaveOptions object as a parameter.
The following code snippets show how to set output document metadata:
import com.groupdocs.comparison.Comparer;
import com.groupdocs.comparison.options.enums.MetadataType;
import com.groupdocs.comparison.options.save.SaveOptions;
import java.nio.file.Path;
// ...
try (Comparer comparer = new Comparer("source.docx")) {
comparer.add("target.docx");
final SaveOptions saveOptions = new SaveOptions();
saveOptions.setCloneMetadataType(MetadataType.SOURCE);
final Path resultPath = comparer.compare("result.docx", saveOptions);
}
import com.groupdocs.comparison.Comparer;
import com.groupdocs.comparison.options.enums.MetadataType;
import com.groupdocs.comparison.options.save.SaveOptions;
import java.nio.file.Path;
// ...
try (Comparer comparer = new Comparer("source.docx")) {
comparer.add("target.docx");
final SaveOptions saveOptions = new SaveOptions();
saveOptions.setCloneMetadataType(MetadataType.TARGET);
final Path resultPath = comparer.compare("result.docx", saveOptions);
}
import com.groupdocs.comparison.Comparer;
import com.groupdocs.comparison.options.enums.MetadataType;
import com.groupdocs.comparison.options.save.SaveOptions;
import java.nio.file.Path;
import com.groupdocs.comparison.words.revision.*;
// ...
try (Comparer comparer = new Comparer("source.docx")) {
comparer.add("target.docx");
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);
final Path resultPath = comparer.compare("result.docx", saveOptions);
}
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.