Convert Man pages to PDF

Always wanted to watch a man page in a pdf file? It is clearly needed sometimes, especially on mac, since it is the easiest way i know to print a man page or to read it not from a terminal.

The problem is solved easily for both Mac OS and linux. I had to add control for <code>pstopdf</code> too, since on mac it is called that way and has different parameters (but you may have <code>ps2pdf</code> installed with macports anyway).

#! /bin/bash

if [ $# -eq 1 ] ; then
    to_pdf=$(which ps2pdf)
    if [ -z "$to_pdf" ] ; then
        to_pdf=$(which pstopdf)
    fi

    name="$1"
    case "$to_pdf"  in
        *pstopdf) man -t "$name" | "$to_pdf" -i -o "$fname.pdf" ;;
        *ps2pdf)  man -t "$name" | "$to_pdf" - "$name.pdf" ;;
        *)        man -t "$name" > "$fname.ps"
    esac
    exit $?
fi
echo "Wrong number of parameters"
exit 1

Just call it like man2pdf gcc and you’ll get gcc.pdf

Advertisements

, , , , ,

  1. #1 by Billy on January 31, 2009 - 9:04 pm

    Thanks for the script. Having a pdf of a man file is handy. MacPilot allows man pages to be search and viewed with clickable links but don’t have any ability to print out as such.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: