Skip to content
Guides

Content Comparison

Comparing the content of two versions of PDF files, including text and images, enables the identification of deleted, added, and replaced content. Displaying the differences in a list format supports the ability to click and navigate to the specific change points within the PDF documents.

The steps to perform content comparison are as follows:

  1. Open the two documents for comparison.

  2. Create a content comparison object.

  3. Compare the specified pages.

  4. Retrieve the results of the content comparison.

This example shows how to perform content comparison:

C#
CPDFDocument document = CPDFDocument.InitWithFilePath("File1.pdf");
CPDFDocument dewDocument = CPDFDocument.InitWithFilePath("File2.pdf");
CPDFCompareContent compareContent = new CPDFCompareContent(document, dewDocument);
int pageCount = Math.Min(document.PageCount, dewDocument.PageCount);
for (int i = 0; i < pageCount; i++)
{
    Console.WriteLine("Page: {0}", i);

    CPDFCompareResults compareResults = compareContent.Compare(i, i, CPDFCompareType.CPDFCompareTypeAll, true);
    Console.WriteLine("Replace count: {0}", compareResults.ReplaceCount);
    Console.WriteLine("TextResults count: {0}", compareResults.TextResults.Count);
    Console.WriteLine("Delete count: {0}", compareResults.DeleteCount);
    Console.WriteLine("Insert count: {0}", compareResults.InsertCount); 
}
  • You can compare different content types in a document by setting the type. For example, using CPDFCompareTypeText will only compare text, while using CPDFCompareTypeAll will compare all content.
  • One of the most important steps in generating the comparison results is the ability to change the highlight colors, which makes it easier to see the differences between two versions of a document. The highlight colors of both versions of a document can be changed using the SetReplaceColor, SetInsertColor, and SetDeleteColor properties.