Terminal – Converting Man Pages to HTML or PDF Format

bashcommand linehtmlpdfterminal

The command man bash produces a lot of output. What I desire would be to either search the results or print the results to paper. So, is there a way to convert a man page to a html and/or pdf document.

I would prefer the answer work for not only man bash, but rather for any man page.

I know the output from man bash has been posted on the internet, but usually these posts are not current.

Best Answer

Yes, there are numerous tools to convert manual pages to HTML and PDF.

UNIX Approach

Converting a man page to HTML, PDF, and text provides detailed instructions for macOS:

cat /usr/share/man/man1/osascript.1 | groff -mandoc -Thtml >man_osascript.html

If the file ends in .gz, then substitute the following.

gunzip --to-stdout /usr/share/man/man8/cupsfilter.8.gz | groff -mandoc -Thtml >man_cupsfilter.html

For converting from HTML to PDF:

cupsfilter man_osascript.html > man_osascript.pdf

For other tool chains, see these related questions:

pandoc

Another approach is to use the popular pandoc tool. This tool can convert manual pages to a wide range of formats.

Link x-man-page

macOS's Terminal.app offers a x-man-page URL scheme for pretty printing manual pages. Try opening the link below to see the ls man page:

x-man-page://ls