Created
May 27, 2019 08:34
-
-
Save GroupDocsGists/3460009559be7e1449de5b8564c39cb0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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