PDF Diff

Share:

Compare two PDFs and see added, removed, and unchanged lines side by side. 100% browser-based.

RT-IMG-026 · Image & File
Your browser is too old for this tool’s interactive features. Please update to Safari 13.1, Chrome or Edge 80, Firefox 74 or newer.

PDF Diff

No PDF loaded.
No PDF loaded.
Diff result will appear here.
💡 How it compares: the tool extracts text from both PDFs line-by-line, then compares the lines with Myers' difference algorithm — the one GNU diff and Git use — which finds the fewest added and removed lines that turn one into the other. Lines only in the original show in red on the left. Lines only in the revised show in green on the right. Unchanged lines align across both sides.
Drop the original PDF on the left, the revised PDF on the right.
🔒 Both PDFs stay on your device. Text extraction and diff computation happen entirely in your browser — nothing is uploaded, even for sensitive legal or financial documents. Verify in DevTools → Network.
Advertisement
After results · AD-W1 Responsive · Post-tool — peak engagement

How to compare two PDFs

Drop both PDFs

Left dropzone for the original ("before"), right dropzone for the revised ("after"). Order matters — getting it backwards shows additions as deletions and vice versa.

Click Compare

Both PDFs are text-extracted and split into lines, then compared. The comparison's cost grows with how many lines differ, not with document length: in our tests two 30,000-line documents four lines apart compared in about 10 milliseconds. Text extraction is the slow part. If more than 4,000 lines differ, the tool says the files are effectively different documents instead of grinding through them.

Read the side-by-side result

Red rows on the left are lines only in the original (removed in the revised). Green rows on the right are lines only in the revised (added). White rows are unchanged. By default, long runs of unchanged lines are collapsed with ⋯ N unchanged lines ⋯ markers — untick the collapse option to see everything.

Export the diff

Click Download .diff.txt to save the comparison as plain text, one line per row: two spaces for unchanged, - for removed, + for added. It is a readable listing, not a patch — it has no @@ hunk headers, so patch and git apply will not read it.

Advertisement
After how-to · AD-W2 Responsive

PDF diff — the contract-review tool every junior lawyer secretly wants

Comparing two versions of a document is a daily job in legal, compliance and policy work. A counterparty returns the contract you sent with "minor changes"; a standard operating procedure is reissued; a paper comes back from review. The question is always the same — what exactly changed? — and the usual answers are a paid desktop compare feature or a website that uploads both confidential drafts to its own server. This tool compares them in your browser.

How the comparison works

Each PDF's text is extracted with pdf.js and rebuilt into lines. The lines are then compared with the algorithm Eugene Myers published in 1986, "An O(ND) Difference Algorithm and its Variations", which is the basic algorithm of GNU diff and the default in Git. It finds a shortest edit script: the fewest lines to remove and add to turn the original into the revision — equivalently, the longest run of lines the two share in order. Its cost is proportional to the length of the documents times D, the number of differences, so a long contract with a few edits is quick.

The cost of a Myers diff grows with the number of changes, not the size of the file. A 500-page contract with three amended clauses is a small problem.

What we fixed on 30 September 2026

The page used to fill a complete table with one cell for every pair of lines — the textbook dynamic programme. Two 30,000-line documents need 900 million cells, about 3.6 GB, which no browser tab gets; the page nonetheless said a modern laptop "handles" it. Myers' algorithm gives the same, minimal answer from memory that grows with the differences. Separately, the old line-builder put a space wherever the font changed inside a word, so a word with one bold letter could show as changed when it was not; line building is now shared with our text extractor. And PDFs whose Chinese, Japanese or Korean fonts are not embedded — they rely on standard character maps — used to lose that text entirely; the maps are now loaded.

Limitations to be honest about

This compares the text pdf.js can extract, so formatting, images, layout and signatures are invisible to it. A moved paragraph shows as a removal and an addition, because a line diff has no notion of "moved". A single inserted word that makes a paragraph re-wrap changes every following line of that paragraph, so read changed blocks together. Multi-column layouts can extract in an order that does not match reading order. For a visual, formatting-aware comparison you need a rendering-based compare in desktop PDF software.

Hunt and McIlroy in 1976, Myers in Git, and where + and − came from

01

The Unix diff program is described in Hunt and McIlroy's Bell Labs Computing Science Technical Report #41, dated July 1976: it solved the longest-common-subsequence problem, attending only to certain "candidate" matches.

02

Hunt and McIlroy observed that on real files diff's time and space grew "about as the sum of the file lengths", even though the worst case grows as their product.

03

Eugene Myers' 1986 paper in Algorithmica (volume 1, pages 251–266) is the basic algorithm GNU diff uses, according to GNU diff's own manual.

04

Git offers four diff algorithms — myers, minimal, patience and histogram — and Myers' greedy version is the default. "minimal" spends extra time to guarantee the smallest diff.

05

The unified diff format — the one with @@ hunk headers and +/- lines — was designed by Wayne Davison. In the early 1990s only GNU diff could write it and only GNU patch could apply it.

06

The original Unix diff did not print + and -. Its paper shows edit instructions: "append after line 0", "change lines 3 through 4", "delete lines 6 through 7".

07

Dan Hirschberg showed in 1975 (Communications of the ACM 18, 341–343) that a longest common subsequence can be computed in linear space, instead of a table the size of both files multiplied.

08

A shortest edit script and a longest common subsequence are two views of one answer: if two documents of M and N lines share L lines in order, at least M + N − 2L lines must be removed or added.

09

The gap between old and new here is concrete: for two 30,000-line documents a full comparison table has 900 million cells. Myers' method on the same pair with four edits took about 10 milliseconds in our tests.

10

Line diffs see re-wrapping as change. Insert one word near the start of a paragraph and every following line of that paragraph moves, even though nothing else was edited.

FAQ

  • No. Both PDFs are read into browser memory, text-extracted via pdf.js, and diffed in your browser. Open DevTools → Network and watch — zero outbound traffic. This is the privacy-safe alternative for diffing confidential legal, financial, or HR documents.

  • No — scanned PDFs have no extractable text. You need to run OCR first (Adobe Acrobat's "Recognize Text", or a desktop OCR tool) to get a text layer, then diff. Diff-on-images is a different problem requiring computer-vision techniques not yet in scope.

  • The "Collapse unchanged regions" option (on by default) hides runs of identical lines that aren't near any change. This keeps the diff focused on what actually differs. Untick it to see every line of both documents.

  • No. This is a text diff — it sees the words, not the formatting. If a paragraph changed from regular to bold but the text is the same, the diff shows "unchanged." For visual / formatting comparison, use Adobe Acrobat Pro's Compare Files feature.

  • Document length is rarely the limit now; the number of differences is. Two 30,000-line documents a few lines apart compare in milliseconds. The slow step is extracting the text, which pdf.js does page by page. If more than 4,000 lines differ, the tool stops and says the files are effectively different documents, because a line-by-line comparison of two unrelated files is not useful.

  • A header naming the two files, then every line in order, prefixed with two spaces (unchanged), - (removed) or + (added). It is meant to be read or attached to an email. It is not a unified diff — there are no @@ hunk headers — so patch tools will not accept it.

  • A line diff only knows three things — a line was kept, removed or added — so a moved paragraph appears as removed from its old place and added at its new one. Some commercial compare products detect moves; this tool does not.

  • pdf.js reports text in pieces with their positions, and lines are rebuilt from those: its own end-of-line markers, a change of baseline, and a space only where there is a visible gap. That matches the printed lines for ordinary text, but multi-column pages, tables and text set on a curve can come out in an unexpected order. If a document is too messy, extract both to text with a desktop tool such as Poppler's pdftotext and compare those.

  • A file that opens without a password — owner-password, "restriction-only" protection — can be compared: pdf.js decrypts it for reading. A file that needs a password to open cannot; remove the password first in software that knows it.

  • Yes. The same two files always give the same result — the algorithm has no randomness and no AI. Where more than one minimal answer exists, the tie is always broken the same way.

Method & sources

What this tool implements

  • Until this review the page filled a full (M+1)×(N+1) LCS table: two 30,000-line documents need 900 million cells, about 3.6 GB, which the page said a laptop "handles". The Myers kernel diffs that size with four edits in about 10 ms and matches an LCS oracle on 300 random pairs.
  • The export was called a unified diff compatible with code-review tools; it is a plain line listing with no @@ hunks, and the page now says so.
  • History corrected from the GNU diff manual and Hunt & McIlroy's CSTR #41: the original Unix diff printed ed-style change commands, not +/- lines; unified format was designed by Wayne Davison.

Sources

Advertisement
Pre-footer · AD-W3 728 × 90