PDFs from man pages

This is an old post. It may contain broken links and outdated information.

I’m constantly consulting man pages as I blunder about in bash, and a way to quickly reference man pages while in the middle of something else is very valuable to me. The easiest way, at least for me, is to have the man pages saved somewhere so that I can consult them without breaking away from whatever deep shell-fu I’m immersed in. There’s a quick way to convert man pages into PDFs on OS X, and a slightly different but similarly quick way to do the same thing on Ubuntu.

The OS X way first, since it doesn’t require any extra packages or applications. Just add the following function somewhere in ~/.bashrc:

### Render and display a PDF of a given man page
function pdfman() {
    man -t $@ | pstopdf -i -o /tmp/$1.pdf && open /tmp/$1.pdf

Then, when you type pdfman , the pstopdf binary will take the man page and transform it into a PDF file in tmp, and then open it in Preview. Magic!

There’s a similar command available on Ubuntu, but you need to have the ghostscript package installed so that you’ve got the needed binary available. Once you’ve done a sudo aptitude ghostscript, add the following toyour ~/.bashrc file:

### Render and save a PDF of a given man page
function pdfman() {
    man -t $@ |ps2pdf - /tmp/$1.pdf

This does mostly the same thing as the OS X command, using ps2pdf instead of pstopdf. The most obvious difference is that we didn’t put the open command on the end, since if you’re connected to a GUI-less server there might be no convenient way to display the PDF. However, if you’re running Ubuntu Desktop and you want the PDF to open after generation just like the OS X command does, you can change the line to look like this:

man -t $@ |ps2pdf - /tmp/$1.pdf && gnome-open /tmp/$1.pdf

Now Ubuntu will display the PDF in the system’s default PDF reader.