Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
// For complete examples and data files, please go to
ComparisonSettings comparisonsettings = new ComparisonSettings();
comparisonSettings.StyleChangeDetection = true;
//this setting specify that we want to have change coordinates
comparisonSettings.CalculateComponentCoordinates = true;
comparisonSettings.DetailLevel = DetailLevel.High;
string sourcePath = "source.pdf";
string targetPath = "target.pdf";
string resultPath = "result.pdf";
Comparer comparer = new Comparer();
ICompareResult result = comparer.Compare(sourcePath, targetPath, comparisonSettings);
List<PageImage> resultImages = comparer.ConvertToImages(resultPath);
List<ChangeInfo> changes = new List<ChangeInfo>(result.GetChanges());
//below the one of cases how we could use changes coordinates.
//we are passing through pages object and draw a rectangle in the coordinates of changes
foreach (PageImage image in resultImages)
Bitmap bitmap = new Bitmap(image.PageStream);
using (Graphics graphics = Graphics.FromImage(bitmap))
foreach (ChangeInfo changeInfo in changes)
//if something was Inserted draw a Blue rectange
if (changeInfo.Type == TypeChanged.Inserted)
graphics.DrawRectangle(new Pen(Color.Blue), changeInfo.Box.X, changeInfo.Box.Y, changeInfo.Box.Width, changeInfo.Box.Height);
//if something was Deleted draw a Red rectange
if (changeInfo.Type == TypeChanged.Deleted)
graphics.DrawRectangle(new Pen(Color.Red), changeInfo.Box.X, changeInfo.Box.Y, changeInfo.Box.Width, changeInfo.Box.Height);
//if something was Changes draw a Green rectange
if (changeInfo.Type == TypeChanged.StyleChanged)
graphics.DrawRectangle(new Pen(Color.Green), changeInfo.Box.X, changeInfo.Box.Y, changeInfo.Box.Width, changeInfo.Box.Height);
bitmap.Save(savePath + @"/Result_Pages/result_" + image.PageNumber + ".png");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment