BASALT · JOURNAL

How to check if two PDFs are identical on a Mac

2026-10-30 · how to check if two pdfs are identical

To check if two PDFs are identical on a Mac, compare their SHA-256 digests in Terminal with shasum -a 256 first.pdf second.pdf. If the two digests match, the files are the same byte for byte. If they differ, the files differ somewhere, but that doesn't mean the documents say different things.

Two PDFs made from the same document at different moments almost never match exactly, because most PDF writers store the time of writing and a file identifier, and both change when the file is written again. So "identical" has four meanings, and the right check depends on which one you need.

Four meanings of identical

Same bytes means the files are copies of one another. A download that arrived intact, or a file you duplicated in Finder, is identical in this sense, and a checksum proves it.

Same text means the words on the pages are the same, whatever the file's internals. Same appearance means the pages look alike when rendered. Same metadata means the author, title, dates and producer match. A pair of files can pass any one of these and fail the others, so decide which question you're asking before you pick a tool.

Byte for byte: shasum and cmp

A SHA-256 digest is a fingerprint of the whole file. This command prints one for each file:

shasum -a 256 first.pdf second.pdf

If the two 64-character strings match, the files are identical. Change one byte anywhere and the digest changes completely. A plain copy of a test file gave the same digest as the original on macOS 15.

To see where two files part ways, use cmp. It prints nothing if the files are identical, or the position of the first difference if not:

cmp first.pdf second.pdf

To count how many bytes differ, list them all and count the lines:

cmp -l first.pdf second.pdf | wc -l

A small count means the files are almost the same, and a count near the file size means they have little in common. Both commands only read files, and neither changes them.

Why identical-looking PDFs don't match

On macOS 15.6, the same content written twice by the same code, one second apart, produced two files with different SHA-256 digests. The files had the same size and the same pages, and cmp -l counted 58 differing bytes. A repeat run counted 60, so the exact number varies, but every differing byte sat in the /CreationDate, the /ModDate or the file /ID.

The dates are the moment of writing. The trailer /ID is a pair of identifiers: the PDF specification says the first is meant to stay the same for the life of the document and the second changes when it's updated. The writer in the test generated a fresh pair each time. Print the trailer of each file to see them:

qpdf --show-object=trailer first.pdf
qpdf --show-object=trailer second.pdf

Install qpdf with brew install qpdf if you don't have it. Compare the /ID lines. In the test pair they were different strings, even though the pages were the same.

To see the stored dates and every other difference in readable form, expand both files and compare the copies:

qpdf --qdf --object-streams=disable --deterministic-id first.pdf first-expanded.pdf
qpdf --qdf --object-streams=disable --deterministic-id second.pdf second-expanded.pdf
diff -a first-expanded.pdf second-expanded.pdf

The expanded copies are uncompressed, so diff shows lines such as /CreationDate and /ID instead of binary noise. The -a matters: without it, the macOS diff only reports that binary files differ. --deterministic-id stops qpdf from writing a fresh identifier into each copy, which on its own would make two copies of one file differ. If the only lines that differ are dates and identifiers, the two files hold the same document.

Same text, different bytes

When dates and IDs make a byte comparison useless, compare what the files say. Spotlight can extract the text of a file without indexing it. This command saves each file's extracted text to a small file, and cmp compares them:

mdimport -t -d3 first.pdf 2>&1 | grep kMDItemTextContent > first.txt
mdimport -t -d3 second.pdf 2>&1 | grep kMDItemTextContent > second.txt
cmp first.txt second.txt

If it prints nothing, the extracted text is the same. In the test pair, the two files matched this way even though their digests didn't. Be aware of what this check includes: Spotlight's text extraction also picks up invisible and white text, so two pages can match here and look different. It also says nothing about images, fonts or layout.

For two versions of a contract you want line-by-line differences, not a yes or no, which is the job of a text comparison tool. Comparing two PDFs and comparing contract versions cover that.

What identical doesn't prove

A matching digest proves two files are the same, not that either is trustworthy. A differing digest doesn't prove anyone edited anything, because a harmless re-save changes it. How to tell if a PDF has been edited explains what the file can and can't show.

Digests are also how you confirm a file arrived unchanged. If a sender publishes a SHA-256 value for a document, compute yours and compare the two strings character by character.

Frequently asked questions

How do I check if two PDFs are identical?

Run shasum -a 256 first.pdf second.pdf in Terminal and compare the two digests. If they match, the files are identical byte for byte. If they don't, run cmp to see where they differ, or compare the extracted text if what you care about is the words.

Why do two identical PDFs have different checksums?

Because a PDF stores more than the pages. A save usually writes a creation date, a modification date and a trailer /ID, and those change even when the content doesn't. In a test on macOS 15, two files written one second apart from the same content differed by about 60 bytes, all in those fields.

How do I check if two files are identical on a Mac?

Use cmp first second in Terminal. It prints nothing when the files are byte for byte identical and reports the first differing byte when they aren't. shasum -a 256 does the same job by giving each file a fingerprint, which is handy when the files are on different Macs.

How do I compare two PDFs on a Mac?

It depends on what you want to compare. For identical bytes, use shasum -a 256 or cmp. For the words, extract the text and compare it. For a page-by-page report of added, removed and changed lines, use a text comparison tool.

Does the same file name mean the same file?

No. A name says nothing about the content, and two files with the same name and size can still differ. Compare digests rather than names, sizes or dates.

Can two different PDFs have the same SHA-256?

In practice, no. SHA-256 digests are designed so that different files producing the same value isn't something you'll meet by chance. If two digests match, treat the files as identical.

Does a different file size mean the PDFs are different?

Yes for bytes, since files of different sizes can't be byte for byte identical. But two files that look identical on screen can still differ in size, for instance when one was saved with different compression or extra metadata. The same size doesn't prove they match either, so compare digests.

Doing it in Basalt

Basalt has a Compare tool for the "same text" question. It compares two PDFs at the text level, page by page, and reports added, removed and changed lines, with a blackline export that strikes through removals and underlines additions. It isn't a layout or visual comparison, so a change that only moves things around won't show. Its redaction is reproducible: the same file and the same marks give a byte-identical result, which you can confirm with the shasum command above. Its Inspect report also prints each file's SHA-256 digest in the header. Every tool writes a new file and leaves the original alone. Basalt is $29 once for up to three Macs, with a 24 hour free trial.

Redaction that proves itself

Basalt destroys the content you mark, then re-opens the file it wrote and proves the content is gone before it saves anything. Your documents never leave your Mac.

DOWNLOAD BASALT 2.3.2 BUY $29 FREE FOR 24 HOURS · MACOS 13+