This article guides on how to compare PDF documents using C#. It has the details to set the IDE for the development, a list of programming steps, and a sample code for developing a PDF compare tool using C#. You will learn to compare page by page or compare the two PDFs as a whole without using any third-party tool.
Steps to Compare PDF Files using C#
- Set the environment to use Aspose.PDF for .NET to compare PDF files
- Load both the PDF files into separate objects of the Document class
- Instantiate the ComparisonOptions object for custom settings
- Use the TextPdfComparer namespace and call the ComparePages() method for comparing individual pages
- Use the CompareFlatDocuments() to compare two different files
The above steps describe the process to compare two PDF documents using C#. Load both the PDF files separately into the Document class object and access reference to the target pages from both files. Call the TextPdfComparer.ComparePages() method to compare the pages or call the TextPdfComparer.CompareFlatDocuments() method to compare the complete text of the two loaded files.
Code to Compare Two PDF Files using C#
The above code demonstrates the mechanism for developing a PDF document comparison tool using C#. You can customize the process by setting the list of excluded rectangular areas in files 1 and 2, flagging to exclude tables from the comparison, or defining the extraction areas from the selected pages. The page comparison returns a list of differences in the pages, whereas the file comparison returns the PDF file containing the details of the differences between the two files.
This tutorial has taught us how to compare PDF files. If you want to merge PDF files, refer to the article on how to merge PDF files using C#.