Get source and target text from files

GroupDocs.Comparison allows you to get source and target texts of specific changes in the output file.

To get a list of changed source and target texts, follow these steps:

  1. Instantiate the Comparer object. Specify the source document path or stream.
  2. Call the add() method. Specify the target document path or stream.
  3. Call the compare() method.
  4. Call the getChanges() method.

The following code snippets show how to get specified texts from a file.

Get source and target text from a local disk

const comparer = new groupdocs.comparison.Comparer(sourcePath);
    comparer.add(targetPath);
    const resultPath = comparer.compare(outputPath);
    let changes = comparer.getChanges();
    for (ChangeInfo change : changes) {
        System.out.println();
        System.out.println("Source text: " + change.getSourceText());
        System.out.println("Target text: " + change.getTargetText());
    }

The result is as follows:

Get source and target text from a stream

const comparer = new groupdocs.comparison.Comparer(sourceInputStream);
    comparer.add(targetInputStream);
    const resultPath = comparer.compare(outputPath);
    let changes = comparer.getChanges();
    for (ChangeInfo change : changes){
        System.out.println();
        System.out.println("Source text: "+change.getSourceText());
        System.out.println("Target text: "+change.getTargetText());
    }