# How to print Man pages in colors ?



## Nicola Mingotti (Feb 6, 2018)

Hi,

I like to read man pages one the web in colors as in:
https://www.freebsd.org/cgi/man.cgi

I would like to have some of them in pdf, in colors 
as well. Is it possible?

I tried to export them to pdf via browser but they don't come well formatted.
I saw the option of exporting to "pdf" in freebsd.org, there
they come very well formatted but not in colors.

Bye
Nicola


----------



## mrclksr (Feb 6, 2018)

Nicola Mingotti said:


> I would like to have some of them in pdf, in colors
> as well. Is it possible?


Hi Nicola Mingotti ,


```
#!/bin/sh

mandoc -T ps | awk 'BEGIN {
   link = "0.72 0.07 0.03";
   bold = "0.6 0.4 0";
   italic = "0.0 0.5 0.07";
   normal = "0 0 0";
}
{
   if ($0 ~ /\/Times-Bold/) {
       print bold " " "setrgbcolor";
   } else if ($0 ~ /\/Times-Roman/) {
       print normal " " "setrgbcolor";
   } else if ($0 ~ /\/Times-Italic/) {
       print italic " " "setrgbcolor";
   }
   print $0;
}' | ps2pdf -
```
*Example*

```
% zcat /usr/share/man/man1/mandoc.1.gz | ./colorman > mandoc.pdf
```


----------



## Nicola Mingotti (Feb 7, 2018)

Thank you, I just tried, colors perfercly match the web version!


----------



## Nicola Mingotti (Feb 7, 2018)

Starting from mrclksr code I wrote a bit longer script that can be used as

```
$> colormanpdf.rb csh
```
and voila', here is the colored pdf 
The script requires Ruby, it is attached.


----------

