Apple - How to produce an A4-format pdf of an man page?
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 .......