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.

I've got a modestly large document (60 pages or so), of technical documentation, in two versions (one of them improved). Unfortunately, I seem to have lost the source of the older version (but I do have the code for the most up-to-date document).

I'd like to compare the two versions of the document (in PDF format) and see what got changed between the two, preferably in a diff-like format.

Not a whole lot changed between the two versions, but minor details are important and could be easily overlooked.

Suggestions how to to this efficiently and effectively will be deeply appreciated. Non-TeX related solutions also welcome, including non-free ones.

I should mention that the documents contain exclusively text, with very few figures and tables, and modest amount of formulae.

Edit: The documents were created with pdfLaTeX by myself, and if you think there's relevant information in the packages I used, I can provide that as well.

Edit 2: A lot of good and promising answers! I will make an effort to try them all one of these days, and will post an update here with the result. This might make a good community wiki.

share|improve this question
Without the source of the older document, it's going to be tricky. Otherwise latexdiff would have worked... –  Seamus Oct 25 '10 at 15:48
It all depends what information about the text is stored, so we'll need more information to help you. Do you know what software was used to create it? What does pdfinfo say about the document? Have you looked at it inside Acrobat, to see, e.g., if text can be edited? –  Charles Stewart Oct 25 '10 at 16:59
See also Comparing the output of two PDFs. –  Speravir Feb 20 at 2:18
add comment

7 Answers

up vote 19 down vote accepted

I've made a quick comparison between some of the methods suggested here. This answer will be a community wiki, and I will made this the accepted one. Hopefully nobody will mind the loss of 15 rep. I upvoted all useful answers, and I urge you to do the same -- all of them were ideas with potential.

  1. Adobe Acrobat Professional -- Compare files

    I've used Acrobat 8 for this test (this is probably the first time I thank the Powers-That-Be that my organization is Windows-mostly shop). Setting this up is easy enough -- Go to Advanced->Compare documents..., and fill in the blanks. That was easy, I thought. Well..

    Pro tip -- Don't choose Detailed analysis (slow). You'll thank me later. I did the first time around, and this thing had been running for 10 minutes, and let's just say that Acrobat is now the proud owner of the World Prize of Ridiculous Memory Consumption, with the whopping 750 (seven hundred and fifty, not a typo) MB. This only reminded me there's a reason I don't use Acrobat except for proof-reading just before printing.

    I tried side-by-side report with Normal analysis, and that could have worked well if only my revised version didn't have 8 pages or so more than the original. It didn't recognize that the same text is somewhere down in the document -- as far as I can tell, it just put the two documents side by side, more or less, with some fancy useless colouring. Oh dear. I could have done that myself without whipping out Liberia's deficit for a license. At this point I wasn't inclined to try again with the detailed analysis, which supposedly would detect such things.

    I'd give it a -1/10, for having an useless option that doesn't really work, and spectacularly so.

    Update: Geoffrey had different experience with Acrobat in what seems a similar document, and I tried to repeat what he did. On the first try I have used the Page by page comparison option, which was so unsatisfactory, while now I tried the Textual differences. This works as he suggests, although the diff result is kind of useless if one chooses the Consolidated report option, and still difficult to interpret with the Side by side report . It still does not show side-to-side the equal text portions in each document, as one would expect when accustomed to diff format, but rather highliting differently the common text, and text unique to each version. At least, there's a comment on which page of the other document you'd find the matching text, so that's useful, although not exactly user-friendly. Also, I noticed it got confused in some places, matching seemingly random words and word fragments.

    This would improve significantly the score of Acrobat, and I think a 7/10 is appropriate, with two whole points deducted for the non-trivial license fee -- the formula I use is:

    licensePenalty = max(0, len(str(licenseFeeInUSD))-1).

    Otherwise, it works good and the performance is also similar to what Geoffrey observed.

  2. Adobe Acrobat Professional -- Export in .txt format. + diff

    This works kind of. You'd get most of the text right, if it wasn't for the annoying mangling of ligatured glyphs. Also, my text is in Swedish, and has a decent amount of diacritics which also got lost. Hyphenation sneaked through as well (rather annoying -- Swedes have very long words sometimes). The formatting is abysmal, but could probably be fixed with an intelligent $FAVOURITE_INTERPRETED_LANGUAGE script.

    I'd give a 6/10 for the effort, but only because diffing acually works. The text is not quite readable at places, for example words like träff looks like tr".

  3. diffpdf

    I found this little gem when looking for diff-like programs to install on Ubuntu. Available from http://www.qtrac.eu/diffpdf.html. Needs Qt and Poppler.

    This is actually superior to Acrobat's Normal analysis mode -- the differences are nicely highlighted and obvious. It does page-by-page comparison as Acrobat, and there seems to be a way to make better comparisons if you know where you've inserted additional pages, but that wasn't very straight-forward to do, and I couldn't be bothered to look through the document to find which pages exactly were added -- that's kind of the point of using a tool to do it, no?

    I'd give it a 4/10 for this particular problem, although for others with small changes it will work great, and would deserve an 8/10 (the user interface could be a bit confusing).

  4. pdftotext+diff

    For those that don't know, pdftotext is part of the xpdf collection, available from here: http://www.foolabs.com/xpdf/home.html. I used the Linux version on Ubuntu.

    This works better than (2), but ligatured glyphs are substituted with what looks like UTF-8 symbols representing them, like fi, ff, ffl, etc. Quotes got mangled as well, again replaced with an UTF symbol (when writing, I always use the "proper" TeX `` and '' quotes). Text search works perfectly, though, even when using such combinations. The readability is much better, if your favourite text editor understands and renders UTF-8, and the formatting is improved, albeit slightly. Hyphenation, however, got taken care of, which is quite nice. One annoying thing, though -- headers and footers, together with page numbers, find their way into the text document, which could be frustrating when comparing the versions.

    This one deserves a hard 9/10, with points deducted for UTF-8 symbols mangling, and the header and footer issue during conversion (the last creates a lot of "false positives" for diff).

share|improve this answer
Excellent analysis! FYI, from my side and taking this with the usual 'your mileage might vary' rider, it takes Acrobat Pro 9.4.0 on my 3yo Lenovo T61 2core 4GB Win7 notepad around 20 seconds to produce a detailed colour-coded diff of a reasonably complex (economics maths, ligatures, hyphenation, English, no Swedish) 90 page 1 1/2 line spaced academic document. Working set memory consumption goes from 68MB (one document loaded, Acrobat idle) to 180MB (peak, two docs loaded, another being produced), peak cpu utilisation 50%. Overall, I'm pretty happy about Acrobat 9's performance with this task. –  Geoffrey Jones Oct 26 '10 at 13:26
Re the update, re Acrobat Pro: the biggest difference between our setups is probably the version that we run. I dipped into my research fund and upgraded from Pro 8 to 9 a few months ago (gotta love site-wide academic pricing) without noticing much difference in overall speed. I'd never used Compare Documents until Lev's suggestion today, so can't comment on the v8/v9 performance differential. My main use for Pro is the bulk pdf indexer/cataloguer which is grindingly (1/10 rating) slow over 2000+ pdfs. Still, once indexed, I'd rate it 8++ for the improvement it makes to my research workflow. –  Geoffrey Jones Oct 26 '10 at 15:08
Here askubuntu.com/a/297285/16395 you can find an interesting solution for using pdfdiff when pagination changes. It creates two big "scroll" documents with one large page and then use that to compare. –  Rmano Jan 16 at 5:49
add comment

I would try pdftotext and then compare the two text files. This might work if it really is mostly text. For comparing the text files you may need a program that is more advanced than diff since you will have probably have different line breaks in the two files. I'm not sure what to recommend for this.

share|improve this answer
For comparing the text files, you can try the mywdiff script from this answer. –  Jukka Suomela Oct 25 '10 at 17:52
add comment

Adobe Acrobat Pro can do a direct comparison of PDFs. The tool is in the menu at: Document->Compare Documents...

You can choose whether to include or ignore changes that are only of formatting, only in the header/footer, etc. It's pretty good assuming both PDFs were generated using the same workflow (eg, both using pdflatex but with slightly different versions of the source files).

Every time I update my latex packages from the repository, I re-tex some of my large documents (eg my own thesis and some other theses I downloaded) and compare the resulting PDFs this way, in order to see if anything has changed. It's a good way to spot obscure bugs in latex packages, that change linebreaks or spacing for some reason.

share|improve this answer
Upvote for the pro tip in the last paragraph. Great idea, not just for catching subtle differences with updated packages, but for regression testing your own LaTeX programming in the workflow before its release. –  Geoffrey Jones Oct 26 '10 at 0:00
add comment

Adobe Acrobat can dump text from a PDF into a word or other text format. This isn't free, or even cheap, but it should work. You could also try just highlighting all the text in Foxit reader (allows you to copy text from the pdf) and paste it into a plain text file, then use any diff tool to look at it.

But really, you should be using some kind of version control with the .tex source files. This will allow you to avoid such situations in the future. I generally like the DVCS for this (git, mercurial, darcs, bzr) because you can create a local repository and don't have to worry about setting up a central server right away.

share|improve this answer
+1 for mentioning version control. –  Sharpie Oct 25 '10 at 17:53
Word doesn't have decent support for doing diffs. I'd work with Acrobat's PDFXML for this. –  Charles Stewart Oct 25 '10 at 18:57
Funny thing is, I do use version control.. Only SVN got botched in a migration between a local and a server installation, and I lost most of the revisions.. –  Martin Tapankov Oct 25 '10 at 19:22
@mindcorrosive I suggest you smack your IT personal. –  Mica Oct 25 '10 at 19:27
@Mica that would be somewhat undesirable, as I was the one performing the migration.. –  Martin Tapankov Oct 25 '10 at 19:31
show 5 more comments

If you are looking for minor changes then pdfpagediff might be useful for you. The package overlays two pdf files and lets you spot minor changes easily.

It's not useful if the two versions are significantly different.

share|improve this answer
add comment

This is not a complete solution by any means. It uses pdftotext which others have mentioned but it is easier to use for picking up small changes to text such as wording or punctuation. That is, diff shows the whole line as changed with no indication of what changed. This uses a tool which will show differences at the level of individual words etc. I've found this works fine for ligatures like fi, ff etc. so I'm not sure why pdftotext has problems with your files. (One of mine in each case is also pdfLaTeX so I ought to have the same issue.)

#!/bin/bash -

pdftotext a.pdf
pdftotext b.pdf
dwdiff -c a.txt b.txt | less -R

# set vim: nospell: 

My pdftotext is provided by poppler. Currently I have version 0.24.5 although a slightly older version should work, since I used this last year and had no issues with ligatures then.

Caveat: I have no idea how this handles formulae. Moreover, I do know it will miss some errors such as erroneous paragraph breaks or superscripting - or at least make them difficult to spot. [Experience speaks!]

share|improve this answer
add comment

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.