Compare multiple documents with specific compare settings

GroupDocs.Comparison allows to compare more that 2 documents and specify some specific comparison options like styling for detected changes, comparison details level etc.

The following are the steps to compare multiple documents with specific options.

  • Instantiate Comparer objectwith source document path or stream;
  • Call add method and specify target document path or stream. Repeat this step for every target document.
  • Instantiate CompareOptions object and specify desired options;
  • Call compare method and pass CompareOptions object from previous step.

The following code sample shows how to compare multiple documents with specific options.

Compare multiple documents with specific compare settings from local disk

Comparer comparer = new Comparer("C:\\source.pdf");
try {
    comparer.add("C:\\target1.pdf");
    comparer.add("C:\\target2.pdf");
    comparer.add("C:\\target3.pdf");

    final StyleSettings styleSettings = new StyleSettings();
    styleSettings.setFontColor(Color.YELLOW);

    CompareOptions compareOptions = new CompareOptions();
    compareOptions.setInsertedItemStyle(styleSettings);

    comparer.compare("C:\\result.pdf", compareOptions);
} finally {
    comparer.dispose();
}

Compare multiple documents with specific compare settings from stream

Comparer comparer = new Comparer(new FileInputStream("C:\\source.pdf"));
try {
    comparer.add(new FileInputStream("C:\\target1.pdf"));
    comparer.add(new FileInputStream("C:\\target2.pdf"));
    comparer.add(new FileInputStream("C:\\target3.pdf"));

    final StyleSettings styleSettings = new StyleSettings();
    styleSettings.setFontColor(Color.YELLOW);

    CompareOptions compareOptions = new CompareOptions();
    compareOptions.setInsertedItemStyle(styleSettings);

    comparer.compare(new FileOutputStream("C:\\result.pdf"), compareOptions);
} finally {
    comparer.dispose();
}

More resources

GitHub Examples

You may easily run the code above and see the feature in action in our GitHub examples:

Free Online App

Along with full-featured Java library we provide simple, but powerful free Apps. You are welcome to compare your DOC or DOCX, XLS or XLSX, PPT or PPTX, PDF, EML, EMLX, MSGand other documents with free to use online GroupDocs Comparison App.