GroupDocs.Comparison allows you to adjust the appearance of the output document.
By default, changes from the two input files (source and target files) are added to the output document and highlighted. Use the ShowInsertedContent and ShowDeletedContent properties to configure the content of the output file.
Use the LeaveGaps property to adjust the display of the output document, which replaces the changed content with empty lines. To use this property, activate the ShowInsertedContent and ShowDeletedContent properties.
The following code snippet shows how to get the desired result
'use strict';// Import the GroupDocs Comparison Node.js SDK
constgroupdocs=require('@groupdocs/groupdocs.comparison');// Define file paths for source, target, and result documents
constsourcePath='sample-files/source.docx';consttargetPath='sample-files/target.docx';constresultPath='result.docx';// Initialize comparer with the source document
constcomparer=newgroupdocs.Comparer(sourcePath);// Add the target document to be compared
comparer.add(targetPath);// Create comparison options object
constoptions=newgroupdocs.CompareOptions();// Do not display inserted content in the result
options.setShowInsertedContent(false);// Do not display deleted content in the result
options.setShowDeletedContent(false);// Keep gaps where deletions occurred
options.setLeaveGaps(true);// Execute comparison and save the result to the specified path
comparer.compare(resultPath,options);// Terminate the process with a success exit code
process.exit(0);
This example creates a Comparer instance with the source document, adds the target document, and creates a CompareOptions object. It configures the output to hide both inserted and deleted content by setting setShowInsertedContent(false) and setShowDeletedContent(false), then enables gap lines by setting setLeaveGaps(true). When the comparison is performed, instead of showing the actual changed content, empty lines (gaps) will be inserted where changes occurred, providing a cleaner view of the document structure.
The result is as follows:
Default result
Result without LeaveGaps property
Default result
Result with LeaveGaps property
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.