Change detection algorithms of GroupDocs.Comparison allow you to detect changes in different document parts and blocks:
Text blocks - paragraphs, words and characters
Tables
Images
Shapes etc.
GroupDocs.Comparison highlights detected changes with different colors:
Added – blue
Modified – green
Style – green
Deleted – red
You can customize the changes styling scheme using different formatting - italic, bold, underlined, strike-through, etc.
The following code snippets show how to compare two documents:
Compare local documents
The following example compares two local documents from the file system and saves a new document that highlights all differences.
'use strict';// Import the GroupDocs.Comparison for Node.js via Java SDK
constgroupdocs=require('@groupdocs/groupdocs.comparison');// Define paths to the source (original) and target (modified) documents
constsourcePath='sample-files/source.docx';consttargetPath='sample-files/target.docx';// Specify the path of the result document that will contain the comparison output
constresultPath='result.docx';// Create a Comparer instance for the source document
constcomparer=newgroupdocs.Comparer(sourcePath);// Add the target document to be compared against the source
comparer.add(targetPath);// Run the comparison and save the result document
comparer.compare(resultPath);// Exit the process after the comparison is finished
process.exit(0);
This example performs the following operations:
Instantiates the Comparer object with the source document path or stream.
Calls the add() method to specify the target document path or stream.
Invokes the compare() method to generate the result document.
The output file is as follows:
Compare documents from a stream
The following example loads documents from Java input streams instead of file paths and then compares them.
'use strict';// Import the GroupDocs.Comparison for Node.js via Java SDK
constgroupdocs=require('@groupdocs/groupdocs.comparison');// Import the Java bridge so we can work with Java input streams
constjava=require('java');// Get a reference to the Java FileInputStream class
letInputStream=java.import('java.io.FileInputStream');// Define paths to the source and target PDF documents
constsourcePdfPath='sample-files/source.pdf';consttargetPdfPath='sample-files/target.pdf';// Define the path for the result DOCX file
constresultDocxPath='result.docx';// Create a Comparer instance using a Java input stream for the source file
constcomparer=newgroupdocs.Comparer(newInputStream(sourcePdfPath));// Add the target document as a Java input stream
comparer.add(newInputStream(targetPdfPath));// Perform the comparison and save the result document
comparer.compare(resultDocxPath);// Exit the process after the comparison is finished
process.exit(0);
In this stream-based scenario:
The Comparer is initialized with a Java input stream for the source document.
The add() method is used to provide the target document as an input stream.
The compare() method runs the comparison and writes the output to the specified result file.
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.