.NET and Java Document Comparison and Difference Checker APIs

Compare PDF, Word, Excel, PowerPoint, Visio, Outlook, OpenDocument, PNG, HTML, CS, CPP, PHP, JSON, and many more file formats in .NET or Java, and perform content, image, and text comparisons.

View all APIsTry our APIs for Free

Compare documents fast and easily

Differentiating between two similar files is a common task for app developers, especially when working with images or text. In many cases, developers need to be able to determine if two files are identical, or if there are any differences between them. This process is known as file comparison, and there are several different ways to do it. Comparisons between documents or images could be done manually, or, you can develop specific applications to automate the comparison process.

Manual document comparison could be laborious, time-consuming, and may require dedicated resources for process accomplishment. Developing a file comparison application can help save time, and make the whole process easier to use. GroupDocs.Comparison for .NET and Java file comparison libraries allow text comparison, image comparison, document comparison, and difference checking among a host of commonly used document and image file formats such as PDF, DOC, DOCX, XLS, XLSX, PPT, PPTX, VSD, ONE, ODT, TXT, DWG, PNG, JPEG, EML, MSG, HTML, in addition to programming language formats like CS, PHP, JS, CPP, JSON, SQL and many more.

Getting Started

Before comparing your documents or images, please check the .NET and Java installation guides to ensure having installed the required components on your system.

Document, image, and text comparison use cases

We'll now take a look at some of the most common use cases of file comparison, as well as how they can be used to compare documents and images in .NET and Java.

Learn to compare PDF and Word Files in .NET and Java

Comparing documents can be tricky especially when you're dealing with different file formats. As a developer, you may need to compare and check differences for the compared data file formats such as PDF, Word, Excel, and PowerPoint documents. There are a few different ways to do this, including building a .NET or Java document comparison application or injecting the code for comparing multi-format files in your web service.

GroupDocs.Comparison APIs for .NET and Java platforms provide you with easy methods for comparing PDF files together with Microsoft Word documents, Excel spreadsheets, and PowerPoint presentations in different frameworks and environments of .NET and Java respectively.

Learn to compare PDF and Word Files in .NET and Java

Compare PDF files in your C# .NET applications

Using the C# code shown below, you can compare PDF files in .NET and check for differences. The resultant document will contain removed content marked in red color, added content in blue color, and modified content (including color or font style changes) in green color.
string sourcePath = @"source.pdf"; // Path to the source pdf document 
string targetPath = @"target.pdf"; // Path to the target pdf document 
string resultPath = @"result.pdf"; // Path to the result pdf document       
using (Comparer comparer = new Comparer(sourcePath))
    CompareOptions compareOptions = new CompareOptions
        DetectStyleChanges = true,
        DetalisationLevel = DetalisationLevel.High
    comparer.Compare(resultPath, compareOptions);
To compare Word, Excel, or PowerPoint documents in .NET instead of PDF using the above code, simply change the source, target, and result document name/extension.

Comparing PDF and Word documents in Java made simple

You can programmatically compare PDF files in Java using only a few lines of Java code shown below. The resultant file will have new additions to the file content marked in blue color, removed content in red color, and changes to the content style (font, color, etc.) in green color.
try (Comparer comparer = new Comparer(“filepath/source.pdf”)) {
If you want to compare Word or Text files in Java, please only change the source, target, and result file name/extension in the above code.

How to develop image comparison and difference checker apps in .NET and Java?

Image comparison is a frequently used functionality while comparing files of different formats. If you are working with a lot of images, it could become tedious to compare them and examine the differences, which is one of the regular features of the image file comparison process.

Therefore, developing an application accurately comparing PNG, JPG, BMP, or GIF images or integrating this functionality into your existing image processing software could be a great and robust addition. GroupDocs.Comparison for .NET and Java file comparison libraries provide all the necessary tools to compare different raster images.

How to develop image comparison and difference checker apps in .NET and Java?

Diff checker and image comparison in .NET

Please use the below-given code snippet to compare PNG, JPG, BMP, or GIF images within your C# .NET image comparison apps. This code shows a JPG image file being used, but you can also load and compare JPG, BMP, or GIF images with the same code.
// Compare JPG, PNG, GIF, and BMP image formats using .NET Image Comparison API in C#
using (Comparer comparer = new Comparer("filepath/soureImage.jpg"))
    CompareOptions options = new CompareOptions();
    options.GenerateSummaryPage = false; // To get the difference summary, set it 'true'

    comparer.Compare("filepath/comparisonResultImage.jpg", options);

Compare raster images in Java

In Java, it’s only a matter of using a few lines of code to compare PNG, JPG, BMP, or GIF images. The following code example shows a JPG image compared, you can similarly use PNG, BMP, or GIF images too within the same code in Java image comparison apps.
// Compare two Images and highlight the differences in Java
Comparer comparer = new Comparer("filepath/image1.jpg")
comparer.add("filepath/image2.jpg ");
comparer.compare("filepath/resultImage.jpg"); // This will return the path of the resultant image. 

Merging and comparison of source code files in .NET and Java

Consider working on a development project distributed among many teams. You could regularly come across the same source code document to which, multiple application developers are contributing by injecting code of various modular segments. To avoid any versioning conflicts, you may have to identify the differences between two such files, and upon completion of the comparison, you can use a programmatic approach to merge them, thus creating a unified source code file ready to be shared across a distributed team.

This and any other scenarios involving the comparison of your source code documents are covered by GroupDocs.Comparison APIs (both .NET and Java) which let you compare code of the source files of your .NET or Java software, use a diff checker, and then merge the files resulting in HTML format output.

Merging and comparison of source code files in .NET and Java

Compare, find differences, and merge source code files in .NET

Given below is the code snippet using which you can merge the source code files in your C# .NET apps:
    using (Comparer comparer = new Comparer(sourcePath))
        ChangeInfo[] changes = comparer.GetChanges();
        for (int i = 0; i < 10; i++)
            changes[i].ComparisonAction = ComparisonAction.Accept;
        for (int i = 10; i < changes.Length; i++)
            changes[i].ComparisonAction = ComparisonAction.Reject;
        comparer.ApplyChanges(File.Create(resultPath), new ApplyChangeOptions { Changes = changes });

Merge the source code files within your Java comparison apps

To compare code and merge source code files in Java, please utilize the following code:
    try (Comparer comparer = new Comparer(sourcePath)) {
        final Path resultPath = comparer.compare(outputPath);
        ChangeInfo[] changes = comparer.getChanges();
        for (int i = 0; i < 10; i++) {
        for (int i = 10; i < changes.length; i++) {
        comparer.applyChanges(resultPath, new ApplyChangeOptions(changes));

Control accepting or rejecting changes in compared documents

In the event of someone mistakenly reverting the changes you have made to a document, the importance of controlling this aspect of document processing grows even greater. File comparison is a great way of avoiding such problems. By comparing two versions of a document, you can see exactly what has been changed, and then decide whether to accept or reject those changes. GroupDocs.Comparison file comparison libraries give you total control over whether or not to accept the changes after having compared two documents (or images) and checked the differences in .NET or Java platforms.

Control accepting or rejecting changes in compared documents

Add or discard differences between compared files in .NET

You can use this powerful feature of the .NET document comparison API and accept or reject the highlighted differences between source and target files using the following C# code:
    using (Comparer comparer = new Comparer("source.docx"))
        ChangeInfo[] changes = comparer.GetChanges();
        changes[0].ComparisonAction = ComparisonAction.Reject;
        comparer.ApplyChanges("resultWithRejectedChange.docx", new ApplyChangeOptions() { Changes = changes, SaveOriginalState = true });
        changes = comparer.GetChanges();
        changes[0].ComparisonAction = ComparisonAction.Accept;
        comparer.ApplyChanges("resultWithAcceptedChange.docx", new ApplyChangeOptions() { Changes = changes });

Masterfully control incorporating content changes after file comparison in Java

Accepting the highlighted changes after comparing data file formats or discarding them in Java is under your control with the help of the following code of the Java document comparison API:
    try (Comparer comparer = new Comparer(sourceFile)) {
        final Path resultPath = comparer.compare();
        ChangeInfo[] changes = comparer.getChanges();
        ApplyChangeOptions changeOptions = new ApplyChangeOptions();
        comparer.applyChanges(resultFileWithRejectedChange, changeOptions);
        changes = comparer.getChanges();
        comparer.applyChanges(resultFileWithAcceptedChange, new ApplyChangeOptions(changes));

We hope you learned a few different aspects of document comparison, image file comparison, text comparison, and difference checking using GroupDocs.Comparison APIs for .NET and Java. If you are looking to compare your PDF, DOC/DOCX, XLS/XLSX, XLSM, PPT/PPTX, PNG, JPG/JPEG, BMP, GIF, TIFF, CAD, RTF, TXT, ODS, and HTML files on the fly using your mobile devices, please check out GroupDocs.Comparison free online apps and perform document comparisons instantly.

Independently automate your document and image processing tasks

Why choose GroupDocs?

Unmatched file formats support

  • All popular file formats supported including documents, images, audio, videos, and ebooks.
  • PDF, DOC, DOCX, XLS, XLSX, PPT, PPTX, PUB, PNG, PSD, ODT, MSG, EML, MP3, MP4, and many more.

Extensively programmable libraries

  • Use GroupDocs APIs to build fully customizable .NET and Java apps.
  • Manipulate your business documents, spreadsheets, presentations, and images any way you like.

Hundreds of supported features

  • Convert Word or Excel to PDF, annotate PDFs, edit DOC, DOCX, or watermark files.
  • Work with esignatures, tables, mail-merge, attachments, shapes, and much more.

Tailored to your needs

  • Free trials and different paid licensing options to choose from.
  • Well-suited to individual users, startups, as well as small and large enterprises.

APIs for Developers

  • Programmatically process your digital documents and images in .NET and Java platforms.
  • Document APIs designed specifically for .NET and Java application developers.

Trusted by users globally

  • Preferred by developers and businesses alike, our libraries are used globally.
  • Generate optimised documents easily in standalone and distributed environments.

Do more with your documents and images

  • Create, render, edit, convert, compare, digitally sign, watermark, and export your files.
  • Experience endless possibilities by creating multi-functional, high-performance apps.

Simple integration and convenient application

  • Enjoy greater flexibility by integrating with your existing software applications.
  • Get up and running using a few lines of code with our super-fast and reliable APIs.

Multiple support channels

  • Need help? Look no further than one of our developer-led support options.
  • Explore the APIs structure, and documentation, or dive into the knowledge base.

Ready to get started?

Download Free Trial