Easy ways to convert a man page
I typically author UNIX man pages for projects a couple of times a year. When I do, the next request I usually receive is to provide a hard copy of the man page as well. Depending on the system, there are a litany of ways to convert a man page into something print ready. Here’s a few:
Adobe PDF – The defacto standard.
In most instances, an Adobe PDF of the file yields excellent results. It’s simple enough to convert a man page to PDF:
$ man -l -Tps /path/to/manpage | ps2pdf14 - manpage.pdf
It’s dead simple, and produces good output. I haven’t run into any issues providing PDF’s in this manner. Groff/troff don’t yet support a PDF as a output device, so for now the man page is output in PostScript and then converted into PDF. If you’re not familar with man, the -l is for a local file. If you want to do this on a known command (i.e. man itself), remove the -l.
PostScript or DVI
To produce PostScript or DVI output, it’s even easier than creating PDF’s as these devices are known to groff/troff.
$ man -l -T[ps|dvi] /path/to/manpage > manpage.[ps|dvi]
Remember that if you need/want to proof this on screen, you’ll need applications that can display PostScript and DVI files. If your on Linux, evince can display both formats. Windows folks are on their own. To determine what devices are available, man man or man groff and look at the -T argument for output device possibilities.
The screen?
Typically when I author man pages and if I use some special formatting or more complex layouts, I want to graphically proof what I’ve done. xman won’t work in these instances, and all that’s really needed is to get a good idea of what it’s going to look like when it’s printed. The normal man command is good enough to get a textual reference, but not a graphical one, and the methods above are too cumbersome for a quick proof. So is there another way to view it?
Yes there is and you get to go really old school with this:
$ troff -man /path/to/manpage | xditview -
or if your using some special macros (like tbl), you can use groff instead and have it invoke gxditview directly instead.
$ groff -X -t -man /path/to/manpage
The nice thing is that you can print from gxditview if necessary. It’s quick and easy to view a man page in this manner and works well for a quick look. If you still want to keep it seriously old school the troff equivalent would be tbl /path/to/manpage | troff -man -|xditview -
Enjoy.