Show gap lines instead of changes

On this page


GroupDocs.Comparison allows you to adjust 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 allows to replace changed content with empty lines. To use this property, activate the ShowInsertedContent and ShowDeletedContent properties.

Follow these steps to adjust appearance of the output document:

  1. Instantiate the Comparer object. Specify the source file path or stream.
  2. Call the add() method. Specify the target file path or stream.
  3. Instantiate the CompareOptions object. Set the ShowInsertedContent, ShowDeletedContent, and/or LeaveGaps properties.
  4. Call the compare() method. Specify the CompareOptions object from the previous step.

The following code snippet shows how get the desired result

import com.groupdocs.comparison.Comparer;
import com.groupdocs.comparison.options.CompareOptions;
// ...

try (Comparer comparer = new Comparer("source.docx")) {
    comparer.add("target.docx");

    CompareOptions options = new CompareOptions();
    options.setShowInsertedContent(false);
    options.setShowDeletedContent(false);
    options.setLeaveGaps(true);

    comparer.compare(resultPath, options);
}

The result is as follows:

Default resultResult without LeaveGaps property
Default resultResult with LeaveGaps property

On this page