Skip to main content

man2pdf Convert unix manpage to PDF

#!/bin/bash

#############################################################################
# #
# man2pdf #
# a simple bash script to convert a man page to pdf #
# #
# Copyright (C) 2003-2004 Trond Aasan #
# #
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation; either version 2 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program; if not, write to the Free Software #
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #
# #
# If you find this useful in any way, or if you find a bug, #
# feel free to e-mail me. #
# #
# Trond Aasan #
# http://www.aasan.org/ #
# #
#############################################################################

# $Id: man2pdf,v 1.6 2004/01/23 18:35:41 trondaas Exp $

MAN=$(which man)
if [ -z "$MAN" ]; then
echo "man executable not found in path" >&2
exit 1;
fi

GROFF=$(which groff)
if [ -z "$GROFF" ]; then
echo "groff executable not found in path" >&2
exit 1;
fi

GS=$(which gs)
if [ -z "$GS" ]; then
echo "gs executable not found in path" >&2
exit 1;
fi

USAGE="Usage: $0 [options] [outfile]
Options:
-n SECTION man section
-h Print this help message

If no section is specified, use first hit.

If outfile is not specified, write output to .
.pdf in
current directory.
"

unset MANSECT

while getopts 'n:h' opt; do
case $opt in
n )
export MANSECT="$OPTARG"
;;
h )
echo "$USAGE"
exit
;;
\? )
exit 1
;;
* )
echo "Error"
exit 1
;;
esac
done

shift $(($OPTIND - 1))

if [ -z "$1" ]; then
echo "$USAGE"
exit 1
fi

infile=$("$MAN" -w -- "$1") || exit $?

if [ -z "$MANSECT" ]; then
AWK=$(which awk)
if [ -z "$AWK" ]; then
echo "awk executable not found in path. Will not guess man"\
"section" >&2
else
BASENAME=$(which basename)
if [ -z "$BASENAME" ]; then
echo "basename executable not found in path. Will not guess man"\
"section" >&2
else
basename=$("$BASENAME" "$infile")
section=$(echo "$basename" | "$AWK" -F . \
"/$(echo "$1" | tr . '\.')\.([0-9a-zA-Z])(\.gz)?$/{print \$2}")
fi
fi
fi

case "$infile" in
*.gz | *.Z)
CAT=$(which zcat)
;;
*.bz)
CAT=$(which bzcat)
;;
*.bz2)
CAT=$(which bz2cat)
;;
*)
CAT=$(which cat)
;;
esac

if [ -z "$CAT" ]; then
exit 1
fi

if [ -n "$2" ]; then
outfile="$2"
else
if [ -n "$section" ]; then
outfile="$1.$section.pdf"
else
outfile="$1.pdf"
fi
fi

"$CAT" -- "$infile" | "$GROFF" -t -E -Tps -mandoc -ma4 \
| "$GS" -q -sDEVICE=pdfwrite -sOutputFile="$outfile" -dNOPAUSE -dBATCH -sPAPERSIZE='a4' -


[close]

Comments

Popular posts from this blog

Cisco Command "Auto secure"

Cisco Command "Auto secure" In today's article, I'm going to quickly inform you about the Privileged EXEC command named "auto secure". Network administrators (like you) use the "auto secure" command to secure the management and forwarding planes of a router. Another way of saying it is, CCNAs use this command to secure a router by disabling common IP services which can be exploited by attackers to initiate network attacks. When the command is typed on a router, it takes the user (ccna) through a command line-interface (CLI) semi-interactive session (which is also known as the AutoSecure dialogue). Below is the command's syntax: auto secure [management | forwarding] [no-interact | full] [ntp | login | ssh | firewall | tcp-intercept] As you can see, the command can use several "optional" keywords: management - This (optional) keyword is used to only secure the management plane of a router. forwarding - This (optional) keyword is used to...

NetSurveyor :: 802.11 (WiFi) Network Discovery / Scanner Tool

NetSurveyor :: 802.11 (WiFi) Network Discovery / Scanner Tool http://www.performancewifi.net/performance-wifi/main/NetSurveyor.htm NetSurveyor is an 802.11 (WiFi) network discovery tool and, as such, its goal in life is to gather information about nearby wireless access points in real time and display it in a useful way. Similar in purpose to NetStumbler , it includes many more features. The data is displayed using a variety of different diagnostic views and charts. Data can be recorded for extended periods and played-back at a later date/time. Also, reports can be generated in Adobe PDF format. Applications for NetSurveyor include the following: During the installation of a wireless network, as an aid in verifying the network is properly configured and antennas are positioned at locations to achieve efficient transmission / reception -- that is, for use in verifying WiFi coverage and maximizing beacon signal strength Trouble-shooting an existing network or wireless environm...

The Seven Habits

The Seven Habits Habit 1: Be Proactive - Changes starts form within; highly effective people make the decisions to improve their lives through the things that they can influence rather than simply reacting to external forces. Habit 2: Begin with the end with mind. - Develop a principle– centered personal mission statement into long- term goals based on personal principle. Habit 3: Put first thing first. - Spend time doing what fits into your personal mission, observing the proper balance between production and building production capacity. Identify the key roles that you take on in life, and make time for each other. Habit 4: Think win / win - Seek agreements and relationships that are mutually beneficial. In cases where a win / win deal cannot be achieved, accept the fact that agreeing to make “no deal”, may be the best alternative. In developing the organizational culture, be sure to reward win / win behavior among employees and avoid inadvertently rewarding win / lose behavior. Habi...