Recently I had need to produce pdf files of some man pages simple because the are far easier to print and review onscreen. The following snippet added to my .bash_profile does the trick.
# Convert man pages to pdf
man2pdf()
{
m2pfile="/tmp/${1}-m2p.pdf"
if [ ! -s $m2pfile ]; then # is it there and > zero bytes
man -t "${1}" | ps2pdf - > "$m2pfile"
fsize=`du -k $m2pfile | awk '{print $1}'`
echo "Created PDF file in $m2pfile ($fsize KB)"
fi
}
It can trivially be extended to check for things like a $DISPLAY variable and pop up a viewer or request to print. The caching is admittedly crude, but works since /tmp is cleared out periodically. Output looks like:
[bvi@starburst ~]$ man2pdf ls
Created PDF file in /tmp/ls-m2p.pdf (20 KB)



0 responses so far ↓
There are no comments yet...Kick things off by filling out the form below.
Leave a Comment