Compare PDF Documents

GroupDocs.Comparison for Python via .NET compares PDF documents and identifies changes in text, formatting, annotations, and structure. Typical use cases include contract review, legal-document comparison, and any workflow where precise difference detection is critical.

The API:

  • Compares two or more PDF files.
  • Highlights insertions, deletions, and formatting changes.
  • Saves the comparison result to a new PDF or any other supported format.

Steps to compare PDF documents

  1. Create a Comparer instance and load the source PDF file.
  2. Add one or more target PDF files via add().
  3. Call compare() with the result file path.

Example: Compare PDF documents

from groupdocs.comparison import Comparer

def compare_pdf_documents():
    with Comparer("./source.pdf") as comparer:
        comparer.add("./target.pdf")
        comparer.compare("./result.pdf")

if __name__ == "__main__":
    compare_pdf_documents()

source.pdf is the source file used in this example. Click here to download it.

target.pdf is the target file used in this example. Click here to download it.

Binary file (PDF, 279 KB)

Download full output

PDF-specific notes

  • Text vs. images. By default, PDF comparison detects both text and embedded image changes. For text-only review, disable image comparison — see Disable image comparison in PDF documents. Text-only mode is faster and produces less visual noise when the PDFs differ only in scanned figures or watermarks.
  • Annotations and form fields. GroupDocs.Comparison detects changes in PDF annotation text and form-field values alongside body text.
  • Page-level coordinates. Set calculate_coordinates = True on CompareOptions to receive pixel-accurate change locations on each page — useful for overlay UIs. See Get changes coordinates.
  • Password-protected PDFs. Pass a LoadOptions with password set — see Load password-protected documents.
Close
Loading

Analyzing your prompt, please hold on...

An error occurred while retrieving the results. Please refresh the page and try again.