Compare multiple documents with specific compare settings
Compare multiple documents with specific compare settings
Leave feedback
On this page
Note
This feature is available for Microsoft Word documents, Microsoft PowerPoint, and Open Document presentations only.
GroupDocs.Comparison allows you to compare more than two documents and specify specific comparison options like styling for detected changes, comparison sensitivity level, etc.
The following code snippets show how to compare multiple documents with the appropriate options.
Compare multiple documents with specific compare settings from a local disk
The following example compares four DOCX documents and highlights all inserted content with a custom font color.
'use strict';// Import GroupDocs.Comparison for Node.js via Java and Java Color utilities
constgroupdocs=require('@groupdocs/groupdocs.comparison');constjava=require('java');constColor=java.import('java.awt.Color');// Define file paths for the source and three target documents
constsourceFile='sample-files/source.docx';consttargetFile1='sample-files/target.docx';consttargetFile2='sample-files/target2.docx';consttargetFile3='sample-files/target3.docx';constresultFile='output/result.docx';// Initialize the comparer with the source document
constcomparer=newgroupdocs.Comparer(sourceFile);// Add multiple target documents to the comparison set
comparer.add(targetFile1);comparer.add(targetFile2);comparer.add(targetFile3);// Configure visual style for inserted items (e.g., new content in targets)
conststyleSettings=newgroupdocs.StyleSettings();styleSettings.setFontColor(Color.YELLOW);// render inserted text in yellow
// Attach style settings to comparison options
constcompareOptions=newgroupdocs.CompareOptions();compareOptions.setInsertedItemStyle(styleSettings);// Run the comparison and save the result document with styled changes
comparer.compare(resultFile,compareOptions);// Terminate the process with a success exit code
process.exit(0);
This example:
Instantiates the Comparer with the source document path.
Adds several target documents using the add() method.
Creates a CompareOptions instance and configures StyleSettings for inserted items (for example, changing font color).
Calls compare() with the result path and options to produce an output document that highlights changes according to the specified styles.
The result is as follows:
Compare multiple documents with specific compare settings from a stream
The following example performs the same multi-document comparison using Java input streams instead of direct file paths.
'use strict';// Import GroupDocs.Comparison for Node.js via Java plus Java stream/color classes
constgroupdocs=require('@groupdocs/groupdocs.comparison');constjava=require('java');letInputStream=java.import('java.io.FileInputStream');letColor=java.import('java.awt.Color');// Create input streams for the source document and three target documents
constsourceInputStream=newInputStream('sample-files/source.docx');consttargetInputStream1=newInputStream('sample-files/target.docx');consttargetInputStream2=newInputStream('sample-files/target2.docx');consttargetInputStream3=newInputStream('sample-files/target3.docx');// Initialize the comparer with the source document stream
constcomparer=newgroupdocs.Comparer(sourceInputStream);// Add each target document to the comparison list
comparer.add(targetInputStream1);comparer.add(targetInputStream2);comparer.add(targetInputStream3);// Set up style settings for inserted items (e.g., highlight color)
conststyleSettings=newgroupdocs.StyleSettings();styleSettings.setFontColor(Color.YELLOW);// use yellow font color for inserted text
// Configure compare options to use the defined style for inserted items
constcompareOptions=newgroupdocs.CompareOptions();compareOptions.setInsertedItemStyle(styleSettings);// Define the output path where the comparison result will be saved
constresultPath='result.docx';// Execute the comparison and generate the result document
comparer.compare(resultPath,compareOptions);// Terminate the process with a success exit code
process.exit(0);
In the stream-based variant:
The Comparer is initialized with a source document input stream.
Target documents are provided as input streams via multiple calls to add().
A CompareOptions object is created and linked with StyleSettings to format inserted items.
The compare() method is invoked with the destination path and options to generate a combined comparison result.
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.
On this page
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.