Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

I'm looking for a good program to show me the differences between two similar pdf files. In particular, I'm looking for something that doesn't just run diff on an ascii version (with "pdftotext") of the files. This is what pdfdiff.py does.

share|improve this question
Does it have to be open source and free? –  Rinzwind May 6 '11 at 19:56
@Rinzwind: That would be preferable, of course. –  krumpelstiltskin May 6 '11 at 20:09
inetsoftware.de/other-products/pdf-content-comparer/… 2.2 here states it can be used under Linux (runPDFC.sh) but the file is not in the archive (only a bat...) but it is java so maybe renaming it(?) –  Rinzwind May 6 '11 at 20:24
@Rinzwind: i don't know enough about java to figure out why it isn't running. i do: java -cp . -jar PDFC.jar but get a java.lang.NoClassDefFoundError :( –  krumpelstiltskin May 6 '11 at 21:47
@Rinzwind: i ran this on windows; the program is terrible. it creates png that are illegible. –  krumpelstiltskin May 6 '11 at 22:55

2 Answers 2

You can use DiffPDF for this. From the description:

DiffPDF is used to compare two PDF files. By default the comparison is of the text on each pair of pages, but comparing the appearance of pages is also supported (for example, if a diagram is changed or a paragraph reformatted). It is also possible to c> ompare particular pages or page ranges. For example, if there are two versions of a PDF file, one with pages 1-12 and the other with pages 1-13 because of an extra page having been added as page 4, they can be compared by specifying two page ranges, 1-12 for the first and 1-3, 5-13 for the second. This will make DiffPDF compare pages in the pairs (1, 1), (2, 2), (3, 3), (4, 5), (5, 6), and so on, to (12, 13).

share|improve this answer
This is the best I've seen. The only issue I see is that it compares the pdfs page-for-page. So if you add a paragraph on say, page 1, the beggining and end of every page after that does not match. :( –  krumpelstiltskin May 8 '11 at 0:21
I think the link is no longer correct. The new version 3.* seems to be available only for windows. The old version 2.* can still be installed via sudo apt-get install diffpdf, though. –  peq Apr 9 '14 at 15:48
up vote 9 down vote accepted

I just figured out a hack to make DiffPDF (the program suggested by @qbi) usable for more than minor changes. What I do is concatenate all pages pdfs into a long scroll using pdfjam and then compare the scrolls. It works even when large sections are removed or inserted!

Here is a bash script that does the job:

# Compare two PDF files.
# Dependencies:
#  - pdfinfo (xpdf)
#  - pdfjam  (texlive-extra-utils)
#  - diffpdf

MAX_HEIGHT=15840  #The maximum height of a page (in points), limited by pdfjam.

TMPFILE1=$(mktemp /tmp/XXXXXX.pdf)
TMPFILE2=$(mktemp /tmp/XXXXXX.pdf)

usage="usage: scrolldiff -h FILE1.pdf FILE2.pdf
  -h print this message


while getopts "h" OPTIONS ; do
    case ${OPTIONS} in
        h|-help) echo "${usage}"; exit;;
shift $(($OPTIND - 1))

if [ -z "$1" ] || [ -z "$2" ] || [ ! -f "$1" ] || [ ! -f "$2" ]
  echo "ERROR: input files do not exist."
  echo "$usage"

    #Get the number of pages:
pages1=$( pdfinfo "$1" | grep 'Pages' - | awk '{print $2}' )
pages2=$( pdfinfo "$2" | grep 'Pages' - | awk '{print $2}' )
if [[ $pages1 > $pages2 ]]

     #Get the paper size:
width1=$( pdfinfo "$1" | grep 'Page size' | awk '{print $3}' )
height1=$( pdfinfo "$1" | grep 'Page size' | awk '{print $5}' )
width2=$( pdfinfo "$2" | grep 'Page size' | awk '{print $3}' )
height2=$( pdfinfo "$2" | grep 'Page size' | awk '{print $5}' )

if [ $(bc <<< "$width1 < $width2") -eq 1 ]
if [ $(bc <<< "$height1 < $height2") -eq 1 ]

height=$( echo "scale=2; $height1 * $numpages" | bc )
if [ $(bc <<< "$MAX_HEIGHT < $height") -eq 1 ]

    #Make the scrolls:
pdfj="pdfjam --nup 1x$numpages --papersize {${papersize}} --outfile"
$pdfj "$TMPFILE1" "$1"
$pdfj "$TMPFILE2" "$2"

diffpdf "$TMPFILE1" "$TMPFILE2"

share|improve this answer
I made your script whitespace-compatible and added unique tempfiles. I hope you don't mind. –  Glutanimate May 19 '13 at 16:59
Also fixed a small bug where the script would create an empty text file in the working directory. (remember to always use double brackets with if statements that use ">" and related operands.) –  Glutanimate May 19 '13 at 17:10
One last remark: This script will work fine only for DIN A4 sized documents. You will have to adjust the PAGEHEIGHT value to get it to work with smaller documents. I'm sure there's a way to automate this but don't know how atm. –  Glutanimate May 19 '13 at 17:21
Thanks for making the improvements @Glutanimate. I've added support for comparison of pdfs of arbitrary and differing sizes (as long as the pages within each pdf are of uniform size, that is). –  krumpelstiltskin May 19 '13 at 20:11

Your Answer


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.