pdf-diff

repository·primary·Indexed 19 days ago

https://github.com/joshdata/pdf-diff

A Python 3 tool for finding and visualizing differences between two PDF documents. It identifies changed text bounding boxes and provides both JSON output and a visual PNG output highlighting changes with red outlines.

Tokens
379
Snippets
3
Records
4
Agent score
18%

What's inside pdf-diff

  1. How pdf-diff works

    primary

    The tool operates in two main stages:

    1. Text Comparison: It compares the text layers of two PDFs. It serializes the PDFs into bounding boxes, performs a diff using fast_diff_match_patch, and identifies changed text hunks.
    2. Visual Rendering: It rasterizes the changed pages into PNG images (using pdftopng), realigns page coordinates, draws red outlines around the changed text, and crops the image to remove unnecessary margins before stacking the pages into a final output.
  2. Install system requirements for pdf-diff

    primary

    pdf-diff requires libxml2 (>= 2.7.0), libxslt (>= 1.1.23), and poppler. Installation commands depend on your operating system.

    # Ubuntu
    sudo apt-get install python3-lxml poppler-utils
    
    # OS X
    brew install libxml2 libxslt poppler
  3. Compare two PDFs and generate a PNG output

    primary

    To find differences between two PDF documents and generate a single large PNG image that highlights changes with red outlines, run the pdf-diff command followed by the 'before' PDF, the 'after' PDF, and redirect the output to a file.

    pdf-diff before.pdf after.pdf > comparison_output.png