GroupDocs.Comparison detects changes in text (paragraphs, words, characters), tables, images, and shapes across a wide range of formats — Word, PDF, Excel, PowerPoint, HTML, AutoCAD, Visio, Outlook, OpenDocument, images, and more. The full list is available on the Supported document formats page.
By default, GroupDocs.Comparison highlights detected changes with the following colours:
Inserted – blue
Deleted – red
Style changed – green
These are the defaults — you can override colours, fonts, and other styling via the InsertedItemStyle, DeletedItemStyle, and ChangedItemStyle properties. See Customize changes styles for details.
Basic comparison workflow
To compare two documents, follow these steps:
Instantiate the Comparer object with source document path or stream.
Call the add() method and specify target document path or stream.
Call the compare() method. It returns the path of the result document.
To control how the comparison is performed and how the result is rendered, pass a CompareOptions object to the compare() method. These options work with any supported document format:
Using a format-specific subclass is recommended when comparing a known document type — it makes Word-only or PDF-only settings discoverable and prevents you from passing irrelevant options.
The example below compares only the first two pages of two PDF documents and lays the result out side by side:
importcom.groupdocs.comparison.Comparer;importcom.groupdocs.comparison.options.PagesSetup;importcom.groupdocs.comparison.options.PdfCompareOptions;// ...
try(Comparercomparer=newComparer("source.pdf")){comparer.add("target.pdf");PagesSetuppagesSetup=newPagesSetup();pagesSetup.setStartPage(1);// 1-based, inclusive; null means "from the first page"
pagesSetup.setEndPage(2);// 1-based, inclusive; null means "to the last page"
PdfCompareOptionsoptions=newPdfCompareOptions();options.setDisplayMode(PdfCompareOptions.ComparisonDisplayMode.SIDE_BY_SIDE);options.setPagesSetup(pagesSetup);comparer.compare("result.pdf",options);}
Configure loading with LoadOptions
While CompareOptions controls how documents are compared, LoadOptions controls how the source and target files are loaded into the Comparer. It is passed to the Comparer constructor and to add(), before any comparison runs.