Get source and target text from files
Leave feedback
On this page
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:
- Instantiate the Comparer object. Specify the source document path or stream.
- Call the add() method. Specify the target document path or stream.
- Call the compare() method.
- Call the getChanges() method.
The following code snippets show how to get specified texts from a file.
try (Comparer comparer = new Comparer(sourcePath)) {
comparer.add(targetPath);
final Path resultPath = comparer.compare(outputPath);
ChangeInfo[] 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:
try (Comparer comparer = new Comparer(sourceInputStream)) {
comparer.add(targetInputStream);
final Path resultPath = comparer.compare(outputPath);
ChangeInfo[] changes = comparer.getChanges();
for (ChangeInfo change : changes){
System.out.println();
System.out.println("Source text: "+change.getSourceText());
System.out.println("Target text: "+change.getTargetText());
}
}
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.