To save output document in different format, 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. Specify the result document path with the required format.
The following code snippet shows how to save comparison result in different format:
importcom.groupdocs.comparison.Comparer;importjava.nio.file.Path;// ...
try(Comparercomparer=newComparer("source.txt")){// Add target document
comparer.add("target.txt");// Compare and save comparison result
finalPathresultPath=comparer.compare("result.pdf");}
Warning
On Java 17 and later, start the JVM with --add-opens java.base/java.io=ALL-UNNAMED when saving a text comparison result to a file with a different extension. Without this flag the result file is written as plain text regardless of its extension.