Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sometimes I want to compare the results of two different settings to see which gives better results (e.g. during the final fine tuning before handing in a document). Such settings can result in small changes in the location of words and other elements of the document.

Motivation

Seeing the documents side-by-side on screen is not always enough, and the cost of printing is too great.

  • Is there a method for overlaying two resulting PDFs (e.g. one PDF is transparent) so that the differences can be easily compared?
  • What other methods can one use to compare two PDFs?
share|improve this question
3  
See also: How to track changes between PDFs? –  Martin Tapankov Nov 28 '11 at 8:11
    
Another tool to consider is <a href="antennahouse.com/antenna-house-regression-testing-system/…;. Its not free, but it does a good job. –  user3165987 Jan 6 at 15:55

7 Answers 7

up vote 28 down vote accepted

You can try pdfpagediff package (not on CTAN):

\usepackage{pdfpagediff}
\layerPages[<optional page numbers>]{<file1>}{<file2>}
share|improve this answer

Check:

http://river-valley.com/looking-for-minute-changes-in-pdf-files/

and

http://soft.rubypdf.com/software/diffpdf

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

http://portableapps.com/apps/utilities/diffpdf_portable

share|improve this answer
4  
I'm a very happy user of diffpdf. The acutal developer's page is http://www.qtrac.eu/diffpdf.html where you also can find links to a precompiled Mac version. –  Florian Nov 28 '11 at 11:41
    
Could you please include some information on diffpdf in your post for completeness (and in case the links die). –  N.N. Nov 29 '11 at 19:22

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
share|improve this answer
    
The comparison fails. Error: compare: image widths or heights differ XY.pdf' @ error/compare.c/CompareImageCommand/962`. I'm on Linux. –  Keks Dose Jul 27 '12 at 9:54
    
@KeksDose: Looks like your two PDFs don't have the same size, but this is a requirement with this code. –  Martin Scharrer Aug 8 '12 at 17:49

Imagemagick provides a compare utility to compare the differences between two image files. The compare-pdfs.sh script from the ConTeXt test suite splits the pdf into multiple pages and then uses imagemagick's compare to compare each page.

share|improve this answer

You can open the two pdf files as a layers of a single image in GIMP, and make the top layer semitransparent. You can also set the top layer to "subtract" or "difference" mode, so you will clearly see the differences between the two layers.

share|improve this answer

This is probably not the best tool for your particular use case, but the hint may be useful for other users who look for "Comparing the output of two PDFs" in a more general sense:

Adobe Acrobat Pro (unfortunately not the free Reader) provides a pretty good "Compare Documents..." feature, which produces a page-wise "diff PDF" out of two PDF documents. Acrobat does a great deal in not comparing pixels, but logical content (especially text), so that editorial changes are easy to detect.

I use this to check, for instance, if my students have incorporated the changes I asked them to do into the draft of their thesis.

share|improve this answer
1  
While being accurate well presented, AA's comparison feature (at least vers. 9 on the Mac) is terribly slow, frequently crashes the application and has an absurd 250-pages limit. IMO nothing worth purchasing the software for. –  Florian Nov 28 '11 at 11:33
2  
@Florian: Thats true. It might be worthwhile to test the Windows version, though – given that on MacOS in general AA crashes a lot :-( In fact, I lost a lot of commenting and correction work by using AA on OSX; these days I use AA mostly from inside a Fusion VM, that is, under Windows. Ridiculously, this is not only more stable, but also a lot faster than using the native OSX version. –  Daniel Nov 28 '11 at 12:50
2  
My experience is that this Acrobat Pro feature is very good when the changes between documents are minor and local. So, tweaks to a figure or a typo fix that doesn't cause a change of line breaking/pagination that propagates beyond the initial paragraph are fine. A document-wide font change or a floating figure that moves to a different page will cause far too many changes, make the compare process extremely slow and produce so many differences that the result is almost useless. Good for checking tweaks from a coauthor, bad for checking journal-supplied proofs against your manuscript. –  Lev Bishop Nov 28 '11 at 14:43

I've had a similar problem to the one in this thread. However, all the solutions proposed here were not suitable for my situation, since I wanted to compare (mostly) text changes.

Moreover, the changes were not "minimal", and the new document was several pages longer than the old one. For instance, I have not been able to make pdfpagediff work. As for the diffpdf tool, It seems that it can only compare PDFs with the same length, which made it unsuitable for my needs. I also didn't like the output produced when using the compare alternative.

Hence, my suggestion, if you have the LaTex sources, is to use the command latexdiff. It is quite simple, you just have to generate the differences between the .tex and .bbl sources. I've used the following Bash script:

#!/bin/bash

if [[ $# -eq 0 ]]; then
    echo -e "\nUsage: $0 <old file> <new file> [-d | --debug]"
    echo -e "\n\tFile names must be specified without extensions, e.g.:"
    echo -e "\n\t\t'paper' instead of 'paper.tex' or 'paper.bib'"
    echo -e "\n\t-d | --debug do not deletes the generated temporary files.\n"
    exit 0
fi

old=$1
new=$2

# Process old file sources
latex $old
bibtex $old
latex $old
latex $old

# Process new file sources
latex $new
bibtex $new
latex $new
latex $new

latexdiff "${old}.bbl" "${new}.bbl" > diff.bbl 
latexdiff "${old}.tex" "${new}.tex" > diff.tex

# Generate pdf
latex diff
latex diff
dvips -Ppdf -ta4 diff.dvi -o diff.ps 
ps2pdf diff.ps

# If debug, exit, otherwise, remove temporary files
if [[ $3 = "-d" || $3 = "--debug" ]]; then
    exit 0
fi

rm diff.tex diff.bbl diff.aux diff.dvi diff.log diff.out diff.ps diff.spl
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.