Embed PDFs In Firefox With Evince Via Mozplugger


by Paul Arnote (parnote)

If you happen to run the KDE version of PCLinuxOS, whenever you click on a PDF, the file opens in an embedded Okular window inside of Firefox. But what if you are running the E17, LXDE, Xfce, Gnome or Openbox desktop? Surely you won’t be too crazy about installing Okular, which brings in most of KDE with it, along with all of its Qt4.x dependencies. To do that, you might as well just install KDE.

Fortunately, there IS another alternative. Thanks to mozplugger (in the PCLinuxOS repository), you can have Firefox open PDFs in an Evince window embedded right in Firefox. Yep. That’s right. Any PDF file you click on will open in a new tab, populated with the PDF file displayed in an embedded Evince window (with one exception, which we’ll cover later).

How It Works

The whole process of setting this up is easy. First, search for and install mozplugger from the PCLinuxOS repository.

Next, open your terminal program and type the following at the command prompt:

mousepad /home/YourUsernameHere/.mozilla/mozpluggerrc

Replace “mousepad” with your favorite text editor (leafpad, gedit, geany, etc.), and replace “YourUsernameHere” with the login name you used when you signed into your session. Since we’re using the command line, you can also replace “/home/YourUsernameHere” with ~.

Now, enter the following lines into your text editor:

application/pdf: pdf: PDF file
application/x-pdf: pdf: PDF file
text/pdf: pdf: PDF file
text/x-pdf: pdf: PDF file
application/x-postscript: ps: PostScript file
application/postscript: ps: PostScript file
   repeat noisy swallow(evince) fill: evince "$file"

Save the file (just select File > Save and the file will be written to the location you specified on the command line), and restart Firefox.

When Firefox has restarted, go find a PDF file on the web (that shouldn’t be too hard) and click on it. If you did everything properly, you should see the PDF file open in the current tab in Firefox, displayed in an embedded Evince window.

July 2012 issue of The PCLinuxOS Magazine displayed in Firefox, inside an embedded Evince window.

Caveats & Customization

Take note that the magazine PDF downloads will not work using this method, since the download of those files are managed by a *.php script on the magazine web site. In fact, any PDF download managed by a *.php script will bypass Mozplugger. However, once you’ve downloaded the magazine PDF, you can select File > Open File..., then select the magazine PDF file you just downloaded. The magazine PDF will then open in the current tab in Firefox. Of course, it is just as easy to open the PDF file (at that point) in Evince’s own window.

When you installed mozplugger via Synaptic, a default mozpluggerrc file was also installed to your /etc folder. Mozplugger will use the first mozpluggerrc file it finds, looking first in the .mozilla directory in your /home folder, then in a series of other folders in your path. To see the list, along with the order of directories it searches for the mozpluggerrc file, type man mozplugger at the command line. As an insurance policy, a backup mozpluggerrc file is also installed to your /etc directory, named mozpluggerrc.default.

While you could edit the mozpluggerrc file in /etc (you can only edit it as the root user), I think it’s safer to simply create and edit the mozpluggerrc file in your .mozilla folder. It does not require root access to edit, and if you mess things up, you can always just delete it and start over, without fear of losing any functionality. Go ahead and take a look at the mozpluggerrc file in your /etc folder. If you see some functionality you’d like to enable (such as viewing LibreOffice files right in Firefox), copy that section of the mozpluggerrc file in /etc and paste it into the mozpluggerrc file in the .mozilla directory in your /home directory.

Also, if you prefer to use a different PDF viewer than Evince (such as xpdf or epdfview), replace “(evince)” in the last line of the above entry in the mozpluggerrc file with the name of your preferred PDF viewer. Again, check the mozpluggerrc file in your /etc directory for specific examples.

Say you had mozplugger handling the opening of certain file types, but now you want to prevent mozplugger from opening them. Just as easily as you created the mozpluggerrc file, you can edit it to exclude them from having mozplugger handle them. Simply find the relevant section in the mozpluggerrc file and place a # in front of each line related to that file type. The # at the beginning of the line causes mozplugger to treat the line as a comment, and it skips those lines. This way, if you ever want to change back to having mozplugger handle the display of those file types, you only have to remove the #, re-save the mozpluggerrc file, and restart Firefox.

Summary

If you do everything correctly, mozplugger can add a lot of convenience and functionality to Firefox, enabling it to display file types right in its own tabs that you would otherwise have to open in a separate application window. Mozplugger can add a lot of power to an already powerful Firefox.