On this page
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:
Open the two documents for comparison.
Create a content comparison object.
Compare the specified pages.
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, usingCPDFCompareTypeText
will only compare text, while usingCPDFCompareTypeAll
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
, andSetDeleteColor
properties.