Comparing the output of two PDFs

You can try pdfpagediff package:

\usepackage{pdfpagediff}
\layerPages[<optional page numbers>]{<file1>}{<file2>}

Check:

PDFPageDiff

and

DiffPDF (free version)

The first link is a to a Latex package pdfpagediff, which, according to the author will

create a composite PDF by juxtaposing each page of file1.pdf over the corresponding page of file2.pdf or vice-versa. Since the PDFs are transparent, you can notice the slightest change visually by simply flipping through the pages

The other link is to a little windows program call DiffPDF, a PDF comparison tool that shows the differences in PDF files either textually or visually. You will also find it as a portable application at

PortableApps DiffPDF 2.1.3

As Florian mentions in his comment, you can download a Mac version from German CNET

UPDATE 28 Jan 2016

Since I wrote this answer, the DiffPDF you will find on the qtrac.eu's homepage (link in Florian's comment) is commercial software, very expensive and with a very restrictive license. The links in my answer are still valid and link to what probably is an older, free version of the software, or maybe a totally different software. I am not sure.


I use the image comparison tool from Image Magick which is available under Linux and Windows (and also Mac, IIRC). It generates a raster image where everything identical is semi-transparent, but the differences are highlighted in red. One drawback is that you have to raster the PDFs and this has to be done page-wise. For example, to compare the first page of two PDFs you can use:

compare -metric PSNR -density 300 first.pdf[0] second.pdf[0] diff0.png

Where 0 stands for the first page (computers start to count at 0). Replace it with 1 for the second and with 2 for the third page, etc. The density is used for the vector to raster image conversion needed. Use higher values for a higher resolution, which takes more space and conversion time, of course. The optional -metric PSNR option also prints the difference as signal-to-noise ratio.

I wrote myself the following shell script comparepdfs which takes the two PDFs as two arguments and produces <number>diff.png files for all pages which show the differences.

#!/bin/bash

FILEA=$1
FILEB=$2
OUTFILE=$3

if [[ -z "$OUTFILE" ]]; then
    OUTFILE="diff.png"
fi

DENSITY=72

PAGESA=$(pdfinfo "$FILEA" | grep ^Pages: | sed 's/Pages:\s*//')
PAGESB=$(pdfinfo "$FILEB" | grep ^Pages: | sed 's/Pages:\s*//')

if [[ $PAGESA > $PAGESB ]];
then
    PAGES=$(($PAGESA-1))
else
    PAGES=$(($PAGESB-1))
fi

for N in `seq 0 "$PAGES"`; do
    echo "Comparing page $N / $PAGES."
    compare -metric PSNR -density "$DENSITY" "$FILEA[$N]" "$FILEB[$N]" "${N}$OUTFILE";
done

Tags:

Pdf

Comparison