Compare PDFs
Published Updated
Compare two PDFs by their text, one sentence at a time, and see what was added, removed or changed, with the changed words marked inside each sentence. Only the text layer is read, so images, layout and scanned pages are not compared.
What the comparison reports
Text is pulled from each page, cut into sentences at every full stop, exclamation mark or question mark, and the two lists are matched. Results of the page's own diff code in Google Chrome 156, on text standing in for extracted pages:
| Change in the second file | Reported as |
|---|---|
| A number in one sentence | 1 change, with the old and new number marked |
| A word in one sentence | 1 change, with the word marked |
| A new sentence in the middle | 1 addition |
| A deleted sentence | 1 removal |
| Two sentences swapped | 1 removal and 1 addition |
| Dr. Smith to Dr. Jones | 1 change; Dr. is its own unit |
Speed depends on how alike the files are
The matching uses the algorithm in Myers' 1986 paper, which the author describes as performing well when differences are small. That showed in the timings: two 3,000-sentence texts with 30 edits compared in 2 ms, while two unrelated 3,900-sentence texts took 453 ms. Together the files may hold at most 8,000 sentences.
What it reports for real PDF pairs, measured
Pairs of PDFs were generated with pdf-lib and compared in the page's own component in Google Chrome 157, Firefox 155 and Playwright's WebKit build (not the Safari app); the text comes from pdf.js 5.4.624. The three engines reported the same result for every pair.
| Change between the two generated PDFs | Reported |
|---|---|
| Identical copy | No text differences found. |
| One word changed (within to inside) | 1 change, with the old and new word marked |
| One number changed (28 to 29) | 1 change, 28 and 29 marked |
| A price changed ($3.50 to $3.60) | 1 change, $3.50 and $3.60 marked |
| A sentence moved from third to thirtieth place | 1 addition and 1 removal |
| A new page of 12 sentences at the end | 12 additions |
| The last page of 12 sentences removed | 12 removals |
| The same text reflowed (12 pt in 500 pt, then 10 pt in 380 pt) | No text differences found. |
| The same text in Helvetica, Times and Courier | No text differences found. |
| A word broken at a line end with a hyphen (interna-, tionalization) | 1 change: the word is read as interna- tionalization |
| A sentence set in capitals | 1 change, the words that differ in case marked |
| Footers Page 1 of 3 and so on, plus one new page of 12 sentences | 14 additions, 1 removal and 2 changes |
| One page of 12 sentences replaced by a picture | 12 removals |
| A text file against a file of pictures only | 36 removals |
| Two files of pictures only | No text differences found. |
Errors show in the file's own box or under the pair: an encrypted file gives This PDF is password-protected, and a truncated file or a text file named .pdf gives Couldn't read this PDF.
Time for longer files
From the moment the second file was chosen to the result on screen, including reading both files with pdf.js, in milliseconds:
| Pages per file (20 sentences each, 5 sentences edited) | Reported | Chrome 157 | Firefox 155 | WebKit build |
|---|---|---|---|---|
| 1 | 5 changes | 128 ms | 229 ms | 146 ms |
| 10 | 5 changes | 150 ms | 298 ms | 211 ms |
| 50 | 5 changes | 262 ms | 529 ms | 360 ms |
| 100 | 5 changes | 383 ms | 885 ms | 546 ms |
| 150 | 5 changes | 522 ms | 925 ms | 732 ms |
| 210 | Stops: more than 8,000 sentences together (8,400) | 593 ms | 1,286 ms | 807 ms |
The text comes from pdf.js's getTextContent, which normalizes the text it returns unless that option is turned off. Both files go through the same call.
Comparing two versions
Step 1
Add the original and the revised PDF
Each slot takes one unencrypted PDF. A password-protected file is rejected with a pointer to Unlock PDF.
Step 2
Read the summary line
It counts additions, removals and changes. If nothing differs in the text, it says No text differences found.
Step 3
Tick Show only differences, then download
Download Summary saves a .txt with + and - lines for the changes and two spaces before unchanged ones.
Limits
- Text comes from pdf.js, whose output can miss characters positioned at a page edge. The page shows a warning when it suspects that.
- Loading a file that takes more than 30 seconds stops with a message.
- To compare pasted text instead, Compare Text uses the same display.
- Metadata such as author and dates is not compared; PDF Metadata Remover shows it.
Comparison questions
Does it find changes in images or layout?
No. Only the text that a PDF viewer can select is compared. A swapped logo, a moved paragraph position or a changed font goes unnoticed unless the words change too.
Why does it say there are no differences for two scanned PDFs?
Scanned pages are pictures without selectable text, so the reader finds no words in either file and has nothing to compare. Run OCR on the scans first. A page with real text next to a scanned one shows the whole text as added or removed.
How is a price change shown?
A full stop followed by a space or the end of the text ends a sentence, and the dot inside $3.50 does not. The test pair $3.50 and $3.60 gave one change with $3.50 and $3.60 marked.
Why is a moved sentence reported twice?
The comparison finds the shortest list of edits in reading order. Swapping Two and Three in a three-sentence test gave one removal and one addition, not a move.
Is a change of capitals counted?
Yes. Comparing Payment due in thirty days with the same words in capitals marked all five words as changed.
Are the PDFs uploaded?
No. They are read with the pdf.js library in the page, compared there, and discarded when the tab closes.
Why do my page-number footers show up as changes?
A footer is text like any other. With footers reading Page 1 of 3, Page 2 of 3 and Page 3 of 3 in one file and Page 1 of 4 and so on in the other, the result was 2 changes, 1 removal and 2 additions for the footers, next to the 12 added sentences of the new page.
Does reflowed text or a different font count as a change?
No. The same 36 sentences set at 12 pt in a 500 pt column and at 10 pt in a 380 pt column gave no differences, and neither did Helvetica against Times and Courier. A word split with a hyphen at a line end does count: interna- and tionalization compared against internationalization gave 1 change.
What happens with a page that is only a picture?
It holds no text for the comparison. Replacing one page of 12 sentences with a picture gave 12 removals, and two files made only of pictures gave No text differences found.
How many pages can I compare?
Two files of 150 pages with 20 sentences each compared in 522 ms in Chrome 157, 925 ms in Firefox 155 and 732 ms in the WebKit build. Together the files may hold 8,000 sentences; two files of 210 pages with 20 sentences each stop with a message that they have too many paragraphs.