You never stop learning Linux, joining commands with pipes, let’s create somehow an infinite number of new “commands” and applications. Some of them really useful.

This time let’s see how we can convert a man page to a pdf file, so you can freely distribute that pdf. This way everybody may read, print or store it, no matter which OS she is using.

Create a pdf man page

We’ll use man and ps2pdf to achieve this goal.

First, be sure the output of man, is in postscript, so that output can then be converted into pdf, by ps2pdf.

man -t man

Will give you an output like this:

%%Creator: groff version 1.20.1
%%CreationDate: Fri Jan 14 00:13:00 2011
%%DocumentNeededResources: font Times-Roman
%%+ font Times-Bold
%%+ font Times-Italic
%%DocumentSuppliedResources: procset grops 1.20 1
%%Pages: 4
%%PageOrder: Ascend
%%DocumentMedia: Default 612 792 0 () ()
%%Orientation: Portrait
%%PageMedia: Default
%%BeginResource: procset grops 1.20 1
%!PS-Adobe-3.0 Resource-ProcSet
/setpacking where{

This is just the first part.

Now if using pipe we redirect that output to ps2pdf

man -t man | ps2pdf - /tmp/man_manpage.pdf

You are done, now you have pdf version of the man page of man, there you can see what the -t option does:

-t Use /usr/bin/groff -Tps -mandoc to format the manual page, passing the output to stdout. The default output format of /usr/bin/groff -Tps -mandoc is Postscript, refer to the manual page of /usr/bin/groff -Tps -mandoc for ways to pick an alternate format.