Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GroupDocsGists/3460009559be7e1449de5b8564c39cb0 to your computer and use it in GitHub Desktop.
Save GroupDocsGists/3460009559be7e1449de5b8564c39cb0 to your computer and use it in GitHub Desktop.
// For complete examples and data files, please go to https://github.com/groupdocs-comparison/GroupDocs.Comparison-for-.NET
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);
result.SaveDocument(resultPath);
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");
bitmap.Dispose();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment