How to produce an A4-format pdf of an man page?

I know that man -t ls | open -f -a /Applications/Preview.app produce a pdf of the man page of the ls command.

But the pdf produced is in US Letter size (21.59 cm x 27.94 cm).

The man page of man says that -t option use internally /usr/bin/groff -Tps -mandoc -c.

So, according the groff man, I tried this for obtaining A4 size (21 cm x 29.7 cm) in the pdf (A4 size is widely used in Europe):

man -t ls | /usr/bin/groff -Tps -mandoc -c -P-pa4 | open -f -a /Applications/Preview.app.

I obtain the A4 size as desired, but the formatting is ugly (no bold, italic, characters doubled, underscored)...

How to have the good formatting (as in the first command) AND the right size (as in the later command)?


Right now you are running groff twice, once as part of man -t, once on it‘s own on the PostScript file generated by man.

Try

groff -Tps -mandoc -c -P-pa4 /usr/share/man/man1/ls.1 >out.ps
ps2pdf out.ps man-ls.pdf
open man-ls.pdf

or directly

groff -Tps -mandoc -c -P-pa4 /usr/share/man/man1/ls.1 | 
    open -f -a /Applications/Preview.app

To have it work for all man pages accessible to man, a little script will help.

#!/bin/sh
page=$(man -W $1)
if [ -r "$page" ]; then
    groff -Tps -mandoc -c -P-pa4 "$page" | open -f -a Preview.app
fi

Save it as manA4, run chmod +x manA4 once, and then use it as manA4 ls.


In case you are working with compressed man pages (which macOS does not use by default) you need to uncompress them on the fly.

#!/bin/bash
page=$(man -W $1)
if [ -r "$page" ]; then
    if [[ "$page" =~ .*.gz$ ]]; then
        gzcat "$page" | groff -Tps -mandoc -c -P-pa4 | open -f -a Preview.app
    else
        groff -Tps -mandoc -c -P-pa4 "$page" | open -f -a Preview.app
    fi
fi

Edit /private/etc/man.conf by commenting out the line

TROFF       /usr/bin/groff -Tps -mandoc -c

then add this line

TROFF       /usr/bin/groff -Tps -mandoc -c -P-pa4

Now man -t will write ps files in A4 paper size.

man -t ls | open .......