everyday mac tools

Compare two versions of a PDF on a Mac

· 6 min read

macOS does not ship a tool that highlights what changed between two PDFs. What it does ship is enough to answer the question properly: shasum in Terminal tells you whether the files differ at all, Automator’s Extract PDF Text action pulls the words out of each one, and diff shows you exactly which words moved.

That covers text documents well. Scanned pages are a different job, because there are no words in the file to compare, and the last section deals with those.

First, find out whether they differ at all

Before comparing anything, rule out the case where somebody sent you the same file twice under two names.

Open Terminal, type shasum -a 256 with a trailing space, then drag both PDFs from Finder into the window and press Return. Terminal fills in the paths for you. You get two lines of hexadecimal:

shasum -a 256 contract-v1.pdf contract-v2.pdf

Identical hashes mean the files are byte for byte the same document, and there is nothing to compare. Different hashes mean something changed, but they say nothing about what, and this is where people go wrong: two PDFs can hash differently while looking and reading identically. Opening a document and saving it rewrites internal structure and timestamps. Printing a file to PDF re-encodes every page. A checksum answers “is this the same file”, never “is this the same document”.

Read them side by side

For a two-page letter, this is faster than any tooling.

  1. Open both PDFs in Preview, in separate windows.
  2. Hold the pointer over the green button of one window and pick a tiling option, or drag the window to the edge of the screen, so the two sit next to each other.
  3. Set both to the same zoom, then scroll them together.

Two Preview features help more than they look like they will. Tools, Show Inspector gives you page count, page size and the document’s title and author for each file, which catches “this is the wrong version” in a couple of seconds. And View, Contact Sheet shows every page as a grid, so a page inserted or removed halfway through announces itself immediately, which is the change that side-by-side scrolling hides best.

This method finds structural differences reliably and small textual ones almost never. A changed number in a table of forty rows will survive any amount of careful looking.

Compare the words with Automator and diff

This is the built-in route that actually finds a changed number.

  1. Open Automator (in Applications) and create a new Workflow.
  2. From the Library, under PDFs, drag in Extract PDF Text. Set Output to Plain Text and choose an output folder, such as your Desktop.
  3. Drag the first PDF onto the workflow’s input area, or add a Get Specified Finder Items action above and put the file in it.
  4. Run it. You get a .txt file of the document’s text.
  5. Repeat for the second PDF.

Then in Terminal:

diff old.txt new.txt

Lines that only appear in the first file are marked with <, lines only in the second with >. For a document with long paragraphs, whole-line output is coarse, because changing one word reprints the entire paragraph as changed. Splitting on spaces first fixes that:

tr ' ' '\n' < old.txt > old-words.txt
tr ' ' '\n' < new.txt > new-words.txt
diff old-words.txt new-words.txt

Now each word is its own line and the output points at the individual words that changed. diff -y --suppress-common-lines old.txt new.txt gives a two-column view if you prefer reading it that way.

Two honest limits. Text extraction follows the order the text was written into the file, not the order your eye reads it, so multi-column layouts, sidebars and tables can come out interleaved oddly. And extraction gives you words with no idea of where they sat on the page, so a paragraph that moved without changing shows up as a deletion plus an insertion, and formatting changes (a different font, a highlighted clause, a shifted table) do not show up at all.

No Terminal, no Automator

The manual version takes a few minutes. Open each PDF in Preview, select the text with the cursor, copy it, and paste each one into its own TextEdit document (Format, Make Plain Text keeps things simple). Save both as .txt files. You are then where the Automator route leaves you, and the diff commands above apply.

Comparing scans

If you cannot select text in the document, there is no text to extract, and everything above stops working. Each page is an image, and comparing images is a different problem that macOS does not solve for you either.

Two things help. The first is recognition: running optical character recognition over both scans creates a text layer in each, at which point the Automator route works normally, with the caveat that recognition errors show up as differences that are not really differences. Make a scanned PDF searchable on a Mac covers that step.

The second is knowing that pixel-level comparison of scans is usually noise. Two scans of the same page differ everywhere, because the paper sat a fraction of a millimeter differently on the glass. Even two exports of the same digital document differ across every page if one has been through a compression pass: Compress a PDF on a Mac without wrecking the scans covers why re-encoding changes every pixel while changing nothing you can read.

When you need to be sure, not fairly sure

There is a category of comparison where “I read them both and they look the same” is not an acceptable answer: the version that goes to a regulator, the copy produced in litigation, the document you signed against the document that came back. For those, you want a comparison done on the document structure rather than on a text dump.

Basalt has a Compare tool built for that, in a Mac app whose document engine holds no network entitlement, enforced by macOS at the code-signature level, so the files stay on your machine while you work. It is a paid app after a free 24 hours with every tool available. For checking whether a colleague fixed the typo in clause 4, the Automator and diff route above is free and already on your Mac.

What a difference in the file does not tell you

Worth holding on to when the comparison matters. A PDF can be saved incrementally, meaning a new version is appended to the file while the old bytes remain underneath. Two documents that look identical on screen can therefore carry entirely different histories inside them, and a comparison of the visible text will never surface that. If the question you are really asking is whether something was removed from a document rather than changed in it, How to check whether a PDF was really redacted covers where to look.

Questions

Is there a Quick Look or Finder way to compare two PDFs? No. Quick Look shows one document at a time and has no comparison mode. Selecting two files and pressing Space gives you a preview you can flip between, which is occasionally enough for a cover-page check and nothing more.

Why does diff show every line as changed when I only edited one word? Because the extraction wrapped the text differently in the two files, so no line matches. The tr commands above, which put one word on each line, remove that problem entirely.

How do I compare two versions of a form? Compare the filled values rather than the pages. If one copy has been flattened and the other has not, extraction returns different things from each, so flatten both first and compare those.