Compare Word or PDF documents in C#

High-fidelity .NET library to compare two documents in PDF, Word, HTML, TXT, MD and other formats

Using our programming API, you can compare two files and find the difference between them. In other words, our .NET library is a powerful file difference checker. After using Document Comparison API, you can get the result and save it in DOCX, PDF, DOC and some other formats.

What is Document Compare

Comparing documents is a very complex function. But we implemented our solution so that you get the most accurate result. Instead of looking for document differences manually, use our .NET API to compare docs.

Document comparing is performed by comparing words at the level of characters or whole words. In this case, if only a character was changed, the word will be highlighted as the whole changed.

The most popular are Word Compare and PDF Compare. Therefore, we will show the .NET Comparison API using the example of comparing Word files and comparing PDF documents.

Compare PDF files using C#

Comparing PDF files programmatically is a typical task of modern digital workflow. This may be required when you are not sure that your document has not been modified. Or when you know your original PDF has been updated and you want to know how.

To compare two PDFs, just verify them with our .NET library. It allows you to diff PDF and find even small changes that would be invisible to the human eye.

Compare Word documents in C#

To compare two Word documents in C# you need to do the same: diff them using our powerful .NET library through the example below.

Unlike PDFs, Word documents are easier to change, which is why it can be so important to compare Word documents if you need to make sure that some parts of it or an entire file are unchanged.

Comparing two files

To test how our .NET solution works and to diff two files, import files you want to compare and choose an export file format. After files are compared, the document containing the difference of this comparison will be automatically downloaded.

Note that documents to compare should not have any revisions before calling the compare method, so we took care of that in our example:

Compare documents in C#
Input files
Upload the compared file
Run code
Upload the second file to compare
Output format
Select the target format from the list
using Aspose.Words;

var docA = new Document("Input1.docx");
var docB = new Document("Input2.docx");

// There should be no revisions before comparison.
docA.AcceptAllRevisions();
docB.AcceptAllRevisions();

docA.Compare(docB, "Author Name", DateTime.Now);
docA.Save("Output.docx");
Run code

How to compare two text files in C#

  1. Install 'Aspose.Words for .NET'
  2. Add a library reference (import the library) to your C# project
  3. Load two documents to compare
  4. Accept all revisions before calling the 'Compare()' method
  5. Call the 'Compare()' method to compare two docs
  6. Call the 'Save()' method, passing an output filename with required extension
  7. Get the result of compression as a separate file

C# library to compare documents

There are three alternative options to install "Aspose.Words for .NET" onto your system. Please choose one that resembles your needs and follow the step-by-step instructions:

System Requirements

Our product is fully cross-platform and supports all major .NET implementations following '.NET Standard 2.0' specification:

  • Microsoft .NET Framework, starting from the earliest 2.0 version, and ending with the latest '.NET Framework 4.8'
  • .NET Core, starting from the earliest 2.0, and ending with the latest '.NET 6'
  • Mono >= 2.6.7

As far as .NET code doesn't depend on the underlying hardware or operating system, but only on a Virtual Machine, you are free to develop any kind of software for Windows, macOS, Android, iOS and Linux. Just make sure you have installed the corresponding version of .NET Framework, .NET Core, Windows Azure, Mono or Xamarin.

We recommend using Microsoft Visual Studio, Xamarin, and MonoDevelop integrated development environments to create C#, F#, VB.NET applications.

Fore more details please refer to Product Documentation.

Most popular file formats for comparison

5%

Subscribe to Aspose Product Updates

Get monthly newsletters and offers directly delivered to your mailbox.

© Aspose Pty Ltd 2001-2022. All Rights Reserved.