Friday, November 10, 2006

Bringing Up PDF files in Firefox

Recently Ubuntu 6.04 (Dapper Drake) pushed the update to Firefox 1.5.0.7. I had been using Swiftfox, but I was tired of searching for the new upgrades myself, so I went back to the Firefox supplied with my distro. (Of course, Firefox 2.0 is out. I'll get to that when I upgrade to Ubuntu 6.10, aka "Edgy Eft.")

No problem. Except that when I tried to open a PDF I got ... nothing.

Well, not quite nothing. I got a brand new Firefox window. Blank.

I found similar tales of woe in the Ubuntu Forums. No help there.

Finally, in frustration I launched Firefox from the command line an clicked on a PDF file. I got the usual blank window, and a set of error messages from Adobe Acroread, mostly coming down to the fact that it didn't like the way it was called.

Well I wasn't necessarily trying to call Acroread. I'd never successfully opened a PDF file with this version of Firefox. And anyway, I was previously using evince.

N.B.: At this point I should probably mention that after I downloaded 1.5.0.7, my settings in ~/.mozilla/firefox were so hopelessly fraked up that I deleted the directory and started over. This means I hadn't saved the previous preferences, which turns out to be part of the problem.

So what's calling Acroread? The only obvious thing I have installed is mozplugger, a sort of super-plugin for Mozilla & Firefox that tries to make your Linux box handle plugins as if it were a PC.

So I looked in the file /etc/mozpluggerrc. (Why? Because I've played with mozplugger before. Now you know the trick as well.) Sure enough, inside the file was a set of lines telling ol' moz' how to handle PDF files:

application/pdf: pdf: PDF file
application/x-pdf: pdf: PDF file
text/pdf: pdf: PDF file
text/x-pdf: pdf: PDF file
      repeat swallow(documentShell) fill: acroread -geometry +9000+9000 +useFrontEndProgram "$file"
      repeat noisy swallow(Xpdf) fill: xpdf -g +9000+9000 "$file"
      repeat noisy swallow(gv) fill: gv --safer --quiet --antialias -geometry +9000+9000 "$file"

The line that has "acroread -geometry +9000+9000 ..." is the key. This is the command mozplugger uses to launch PDFs if acroread is present on the system. It also has a lot of flags that the current version of acroread doesn't like.

So there are to possible fixes:

  1. Change the offending line. I replaced it with

    repeat swallow(documentShell) fill: acroread "$file" then restarted Firefox and clicked to open a PDF file. Firefox still brings up the blank window, but it also launches acroread and I can read the PDF file.

    Note that you can use any other PDF reader that you want here, it doesn't have to be acroread. Some of the other options are given in mozpluggerrc, as you can see above.
  2. Tell mozplugger to stop working on PDF files. This is fairly easy:
    1. Comment out (with a "#" in the first column) or delete all of the lines referring to PDFs in /etc/mozpluggerrc.
    2. Quit Firefox, if it's running, and delete the file ~/.mozilla/firefox/pluginreg.dat. This will let Firefox bring its plugin database up to date the next time you start it.
    3. Start Firefox, and try to open a PDF file. You'll get the usual dialog box asking what you want to do. Give it the path to your favorite PDF reader and check to box to always do this.
    4. Now PDFs should launch normally.

In retrospect, it looks as though Ubuntu must have updated Firefox and Mozplugger at about the same time I decided to use Firefox rather than Swiftfox and to trash my ~/.mozilla/firefox preferences. The combination of factors messed up reading PDF files. The tail end of the Ubuntu Forum post linked above is the short version of this story.

0 comments: