Skip to content

Instantly share code, notes, and snippets.

@GroupDocsGists
Last active April 18, 2023 08:00
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/bf49902dda69a05f94f88a324f67dd4e to your computer and use it in GitHub Desktop.
Save GroupDocsGists/bf49902dda69a05f94f88a324f67dd4e to your computer and use it in GitHub Desktop.
Compare PDF Documents, Find Differences, and Accept or Reject Changes using C#
/*
* Accept and reject identified changes by comparing PDF documents using C#
*/
using (Comparer comparer = new Comparer(@"path/document-1.pdf"))
{
comparer.Add(@"path/document-2.pdf");
comparer.Compare();
ChangeInfo[] changes = comparer.GetChanges();
// Rejecting the first identified change and it will not be added to result document
changes[0].ComparisonAction = ComparisonAction.Reject;
comparer.ApplyChanges(@"path/rejected-change-result.pdf", new ApplyChangeOptions { Changes = changes, SaveOriginalState = true });
changes = comparer.GetChanges();
changes[0].ComparisonAction = ComparisonAction.Accept;
comparer.ApplyChanges(@"path/accepted-change-result.pdf", new ApplyChangeOptions { Changes = changes });
}
/*
* Compare Multiple PDF Documents using C#
*/
using (Comparer comparer = new Comparer(@"path/document-1.pdf"))
{
comparer.Add(@"path/document-2.pdf");
comparer.Add(@"path/document-3.pdf");
comparer.Add(@"path/document-4.pdf");
comparer.Compare(@"path/compare-result.pdf");
}
/*
* Compare Two PDF Documents and Highlight Changes using C#
*/
using (Comparer comparer = new Comparer(@"path/document-ver1.pdf"))
{
comparer.Add(@"path/document-ver2.pdf");
comparer.Compare(@"path/compared-result.pdf");
}
/*
* Compare Password Protected PDF Documents using C#
*/
using (Comparer comparer = new Comparer(@"path/protected-document-1.pdf", new LoadOptions(){ Password = "SourceFilePassword" }))
{
comparer.Add(@"path/protected-document-2.pdf", new LoadOptions() { Password = "TargetFilePassword" });
comparer.Compare(@"path/compared-protected-docs-result.pdf");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment