Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the '10.4: Use Preview to view formatted man pages' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.4: Use Preview to view formatted man pages
Authored by: doctype on Dec 30, '05 12:10:42PM
Well, here is my 'pman' version of a man-to-pdf convenience script. It first checks for available man pages, then converts the man page to pdf, stores it at a configurable location and then opens it in Preview. If a pdf already exists, the conversion will be left out.

#! /bin/sh

# configure your directory for storage of created PDF (with trailing slash)
pmanpath='/Absolute/path/to/store/location/'

if [ "$1" ]
then
	pdffile="${pmanpath}${1}.pdf"
	if [ -r "${pdffile}" ]
	then
		echo -n "PDF already exists at location "
		echo "${pdffile}"
		open "${pdffile}"
	else
		mantest=`man -w ${1}`
		if [ -z "${mantest}" ]
		then
			echo "No PDF created"
		else
			man -t "$1" | ps2pdf - "${pdffile}"
			if [ -r "${pdffile}" ]
			then
				echo -n "PDF created at location "
				echo "${pdffile}"
				open "${pdffile}"
			else
				echo "Couldn't create PDF for some mysterious reasons"
			fi
		fi
	fi
fi


[ Reply to This | # ]
10.4: Use Preview to view formatted man pages
Authored by: aalegado on Dec 31, '05 03:08:18PM
I didn't have 'ps2pdf' on my system (Tiger, 10.4.3). Instead, I had 'pstopdf' so the original script didn't work for me. I came up with something a little different based on doctype's script.

#! /bin/sh
pathtopdfs='/Absolute/path/to/folder/for/PDFs'
pdffile="$1.pdf"

cd "$pathtopdfs"

if [ "$1" ]
then
	if [ -r "$pdffile" ]
	then
		echo "The PDF for that man page already exists. Here it is..."
		open "$pdffile"
	else
		echo "The PDF for that man page does not exist. Creating it now..."
		man -t "$1" | pstopdf -i -o "$pdffile"
		open "$pdffile" 
	fi
else
	echo "No command specified. Exiting..."
fi
If your intended storage location for the PDFs has spaces in the directory name (e.g. a folder in your Documents folder named "PDFs of man commands"), you can get away with something like:

'/Users/username/Documents/PDFs of man commands'
Also note that the trailing slash isn't needed since I'm using this variable differently.

[ Reply to This | # ]
10.4: Use Preview to view formatted man pages
Authored by: komakino@myvarmi on Jan 01, '06 08:49:36PM

Great script! It should be mentioned that ghostscript needs to be installed in order for the ps2pdf function to be available. You can get it via the Fink or Darwinports projects.



[ Reply to This | # ]