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");}
Note
In versions earlier than 26.10 running 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 those versions write the result file as plain text regardless of its extension. Version 26.10 and later need no flag.