Save comparison result in different format

View as MarkdownMarkdown

Set up your AI agent

Give your coding agent live access to the GroupDocs documentation and API reference through the GroupDocs Docs MCP server — no install, no API key. Learn more

claude mcp add --transport http groupdocs-docs https://docs.groupdocs.com/mcp

Also process documents locally

The GroupDocs.Comparison MCP server lets your agent work with files on your machine; they are never uploaded. It needs the .NET 10 SDK or Docker.

claude mcp add groupdocs-comparison -- dnx GroupDocs.Comparison.Mcp --yes
Folders, licensing and more →

On this page

GroupDocs.Comparison allows you to save output document in different formats.

To save output document in different format, 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. Specify the result document path with the required format.

The following code snippet shows how to save comparison result in different format:

import com.groupdocs.comparison.Comparer;
import java.nio.file.Path;
// ...

try (Comparer comparer = new Comparer("source.txt")) {
    // Add target document
    comparer.add("target.txt");

    // Compare and save comparison result
    final Path resultPath = 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.

See also

On this page