As a university teacher, I often get to read new versions of student essays, and I want to be able to quickly see what changes there are from the old version. Here's how to use the FileMerge application (included in the Xcode developer tools) to view PDF files. In addition, you'll also need the command line utility pdftotext, which you can get from MacPorts.
First you need to install the pdftotext command line utility. It's included in both the Poppler and the Xpdf rendering libraries -- either one will do. With Macports installed, just open a Terminal window and execute one of these commands:
$ sudo port install poppler $ sudo port install xpdfLaunch FileMerge (in Developer » Applications » Utilities), and open its Preferences. On the Filters tab, create a new filer by clicking in an empty row. The Extension should be pdf, and set the Filter to:
pdftotext -layout -nopgbrk -enc Latin1 $(FILE) -Now you can diff PDF files. Note that you can write opendiff on the command line to start FileMerge:
$ opendiff oldfile.pdf newfile.pdfNote that there's a problem with the simple solution above: FileMerge wants the text files to be in Mac-Roman encoding (why, Apple, why?), but pdftotext cannot export to Mac-Roman.
The solution to this problem is to use the built-in command iconv for this conversion. However, this results in a shell script pipe, which FileMerge cannot handle. So, this is what we have to do. Create a file (e.g., convert_pdf_to_macroman_text.sh) with the following contents:
#!/bin/sh pdftotext -layout -nopgbrk -enc UTF-8 "$1" - | iconv -c -f UTF-8 -t MacRomanPut it somewhere (e.g., in a directory ~/bin) and make it executable. In the Terminal, you do that like this:
$ chmod a+x ~/bin/convert_pdf_to_macroman_text.shNow you can set the Filter for PDF files in FileMerge to:
~/bin/convert_pdf_to_macroman_text.sh $(FILE)Now you can view non-ASCII symbols too (such as Swedish ÅÄÖ).
Mac OS X Hints
http://hints.macworld.com/article.php?story=20091116055842805