Windows
ComPDFKit PDF SDK
Guides

ComPDFKit provides two methods to compare documents:

- Overlay Comparison

- Content Comparison

 

 

Overlay Comparison

 

Overlay Comparison is used to visually compare pages of different documents. It’s helpful for things such as construction plans and detailed drawings, as well as other content that requires precise placement.

 

This can be done in ComPDFKit using CPDFCompareOverlay. The process of preparing documents and comparing them involves a few steps to specify how the comparison should happen.

 

Generating the Comparison Document

 

You can use CPDFCompareOverlay to generate a comparison document. First, initialize it with the two versions of a document to be compared, then call the compare function first and the comparisonDocument function next as arguments:

 

CPDFDocument oldDocument = CPDFDocument.InitWithFilePath("***");
  CPDFDocument newDocument = CPDFDocument.InitWithFilePath("***");
CPDFCompareOverlay compareOverlay = new CPDFCompareOverlay(oldDocument,newDocument);
  compareOverlay.Compare();
CPDFDocument comparisonDocument = compareOverlay.ComparisonDocument();

 

By default, the CPDFCompareOverlay will generate a comparison document according to the order of pages, starting from the first page of both versions of the document. If the page you want to compare has moved, or if it’s not the first page, you can specify explicit indices using extra pageRange arguments: 

 

CPDFDocument oldDocument = CPDFDocument.InitWithFilePath("***");
  CPDFDocument newDocument = CPDFDocument.InitWithFilePath("***");
  CPDFCompareOverlay compareOverlay = new CPDFCompareOverlay(oldDocument,"1-5",newDocument,"2-6");
  compareOverlay.Compare();
  CPDFDocument comparisonDocument = compareOverlay.ComparisonDocument();

 

Changing the Stroke Colors

 

One of the most important steps of generating a comparison document is the ability to change the stroke colors, which makes it easier to see the differences between two versions of a document.

 

Setting a different stroke color is usually necessary when trying to compare documents, as this will enable you to make any differences between pages more obvious. This will only affect stroke objects in the PDF, and it will leave the color of other elements, such as text or images, unchanged.

 

The stroke colors of both versions of a document can be changed using the SetOldDocumentStrokeColor and SetNewDocumentStrokeColor properties.

 

You can also change the blend mode used to overlay the new version of a document on top of the old one by changing the SetBlendMode property. Trying out various stroke colors and blend modes will result in different-looking comparison documents, and you can make sure the final result fits your needs.