Visual diff of PDF files in order to determine pixel perfectness

This question has already an accepted answer, but I'd like to give my two cent. We made i-net PDFC that perfectly matches your scenario. It has been made to check reports made with another reporting tool match the output of our reporting software. But its even more powerful. What PDFC does not do is: check image-based pixel perfectness, but it checks, with certain settings, that a document is basically (and visually) the same based on its content. Way more powerful than pure pixel-based comparison.

i-net PDFC can operate visually or command-line based (e.g. to batch process) and works with continuos integration systems. The visual component even allows semitransparent overlaying the two PDF files to have the user check the pixel-perfectnes.

The software is fresh out of beta. Give it a try and let us know what you think. (Yep. I work for the company who made this.)


The most simple, immediately available method to do this: use ImageMagick's compare (which is also available on Windows/Linux/Mac and other).

It can even compare PDF pages (though it uses Ghostscript as its delegate to render the PDF pages to pixel images first):

 compare.exe         ^
    tested.pdf[0]    ^
    reference.pdf[0] ^
   -compose src      ^
    delta.pdf

The resulting delta.pdf will depict each pixel as red which has a different color between the two compared PDF pages. All identical pixels will be purely white. The [0] tell compare to use the first pages of each file for comparison (page count is zero-based).

You can see how this works out with the following example:

 compare.exe                      ^
    http://qtrac.eu/boson1.pdf[1] ^
    http://qtrac.eu/boson2.pdf[1] ^
   -compose src                   ^
    delta.pdf

Here are the respective pages (converted to scaled-down PNGs for web display). The reference page is on the left, the modified page is the middle one, the 'delta-pixel-are-red' image is on the right:

first page second page delta image

A slightly different visual result you can get by skipping the -compose src parameter. Then you'll get the original file's pixels as a gray-shaded background (for context) with the delta pixels in red:

 compare.exe                      ^
    http://qtrac.eu/boson1.pdf[1] ^
    http://qtrac.eu/boson2.pdf[1] ^
    delta.pdf

first page second page delta.pdf

If you don't like the red color for pixel differences, use -highlight-color:

 compare.exe                      ^
    http://qtrac.eu/boson1.pdf[1] ^
    http://qtrac.eu/boson2.pdf[1] ^
   -highlight-color green         ^
    delta.pdf

The default resolution used to render the PDF pages is 72 dpi. Should you need a higher precision, you can switch to 300 dpi using the -density parameter like this:

 compare.exe                      ^
   -density 300                   ^
    http://qtrac.eu/boson1.pdf[1] ^
    http://qtrac.eu/boson2.pdf[1] ^
    delta.pdf

Note, switching to higher densities will slow down the process and create bigger files.

You can even create a *.txt file for the delta image which describes each pixel's coordinates and the respective color values:

 compare                          ^
    http://qtrac.eu/boson1.pdf[1] ^
    http://qtrac.eu/boson2.pdf[1] ^
   -compose src                   ^
   -highlight-color black         ^
    delta.txt

Then simply count the number of total vs. black pixels (sorry, this is Unix/Linux/MacOSX syntax):

 total_pixels=$(( $(cat delta.txt | wc -l) - 1))
 black_pixels=$(( $(grep black delta.txt | wc -l) -1 ))

In the example used for the illustrations above, I get

 total_pixels=500990
 black_pixels=8727

Of course the 'ideal' result would be

 black_pixels=0

diffpdf allows you to compare two PDFs side by side.