Sunday, May 17, 2026

Command line tools to compare PDF files


I recently wanted to compare twp PDF files that seemed to be similar, yet had different file sizes.

After some LLM’ing (is that a word already?) I came to this one-liner that does the trick:
  • diff <(pdftotext file1.pdf -) <(pdftotext file2.pdf -)

This gives a text based comparison. 

Alternatively, I can use pdfdiff to make a screenshot of every page and have these compared against each other automatically.
  • pdf-diff file1.pdf file2.pdf        

No comments: