When a contract or report comes back as a new version, reading both copies side by side is slow and misses small edits. Extracting the text from each version and diffing the two outputs lists every changed passage in one place.
What you need
- Python with pypdf installed
- Two versions of the same PDF
- A diff tool, such as diff on the command line
- A terminal
Step 1: Extract the text from both versions
Use pypdf to extract the text of each PDF into its own plain-text file, keeping the page order the same in both.
Step 2: Diff the two text files
Run diff on the two text files and read the output, which marks lines that were added, removed, or changed between the versions.
Step 3: Verify each change against the pages
Open the changed passages in the PDFs themselves and confirm the diff reflects a real edit, not an extraction difference caused by layout or encoding.
Worked example: synthetic version comparison on a 6-page agreement
The table below is a synthetic example. It shows the expected result of the text diff; no diff was run.
| Location | Change | Verified |
|---|---|---|
| Page 2 | Date changed 1 May to 15 May | Yes, real edit |
| Page 4 | Clause 7 added | Yes, real edit |
| Page 6 | Line order differs | No, extraction artifact |
| Total | 3 differences | 2 real edits, 1 artifact |
Expected result (UNTESTED). two genuine edits are found, a changed date and an added clause, while the third difference is only an extraction artifact and not a real change. This check was not run live; the table shows the expected result for the synthetic example.
Limits
- Text extraction can differ between versions for layout reasons, so every diff hit needs a visual check.
- Changes to images, charts, or scanned pages do not appear in a text diff.
- A diff shows what changed, not whether the change is correct or authorized.
