The following code snippets show how to compare several documents:
Compare several documents from a local disk
'use strict';// Import Java bridge and FileInputStream for handling file streams
constgroupdocs=require('@groupdocs/groupdocs.comparison');constjava=require('java');constInputStream=java.import('java.io.FileInputStream');// Create an InputStream for the source document
constsource=newInputStream('sample-files/source.docx');// source document stream
// Initialize the comparer with the source document stream
constcomparer=newgroupdocs.Comparer(source);// Add the first target document to compare against the source
comparer.add(newInputStream('sample-files/target.docx'));// first target stream
// Add the second target document
comparer.add(newInputStream('sample-files/target2.docx'));// second target stream
// Add the third target document
comparer.add(newInputStream('sample-files/target3.docx'));// third target stream
// Perform comparison and save the result to the specified file
comparer.compare('result.docx');// output file with comparison result
// Terminate the process with a success exit code
process.exit(0);
This example compares multiple documents from disk:
A Comparer instance is created for the source document stream.
Several target document streams are added using the add() method.
The compare() method is called to generate a single result document that aggregates differences across all targets.
The result is as follows:
Compare several documents from a stream
'use strict';// Import Java bridge and set up InputStream class for reading files
constgroupdocs=require('@groupdocs/groupdocs.comparison');constjava=require('java');letInputStream=java.import('java.io.FileInputStream');// Create InputStream for the source document
constsourceInputStream=newInputStream('sample-files/source.docx');// Create InputStream for each target document
consttargetInputStream1=newInputStream('sample-files/target.docx');consttargetInputStream2=newInputStream('sample-files/target2.docx');consttargetInputStream3=newInputStream('sample-files/target3.docx');// Initialize 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);// Execute comparison and save the merged result
comparer.compare('sample-files/result_multiple.docx');// Terminate the process with a success exit code
process.exit(0);
In the stream-based variant:
The Comparer is initialized with the source document stream.
Input streams for each target document are added sequentially via add().
A final call to compare() produces a merged result that reflects changes across all compared documents.
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.
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.