-# pdfman: View Manual Pages as Portable Document Format (PDF) files
+# pdfman: View UNIX manual pages as Portable Document Format (PDF) files
-`pdfman` converts UNIX manual pages to PDF using the `pstopdf(1)` command and
-displays them by calling `open(1)` on the resulting PDF file. This works very
-good on macOS and enhances the useability of the manual pages quite a bit
-because you can use your preferred PDF reader.
+`pdfman` converts UNIX manual pages to PDF documents using Ghostscript's
+`ps2pdf`(1) or Apple's `pstopdf`(1) command (included in macOS up to version 13
+"Ventura") and displays them by calling `open`(1) on the resulting PDF file.
+This enhances the useability of the manual pages quite a bit, because you now
+can make use of your preferred PDF file viewer and all of its functionality.
The conversion is only done once and a cached PDF file gets used for subsequent
invocations for the same topic.
#!/bin/bash
# shellcheck disable=SC2250
#
-# pdfman - View Manual Pages as PDF Files, using pstopdf(1) and open(1)
-# Copyright (c)2010,2013,2016,2019 Barton IT-Consulting, Alexander Barton
+# pdfman - View UNIX manual pages as Portable Document Format (PDF) files
+# Copyright (c)2010,2013,2016,2019,2023 Barton IT-Consulting, Alexander Barton
#
# 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
shift
done
+run_ps2pdf() {
+ # Ghostscript ps2pdf(1)
+ ps2pdf - "$1"
+}
+
+run_pstopdf() {
+ # Apple pstopdf(1)
+ pstopdf -i -o "$1" >/dev/null
+}
+
# Manual page name(s) given?
if [[ -z "$1" ]]; then
# Give man's wtf error ("help message"):
exit $?
fi
# Make sure required tools are available ...
-if ! command -v open >/dev/null || ! command -v pstopdf >/dev/null; then
+if ! command -v open >/dev/null; then
+ man "$@"
+ exit $?
+fi
+
+# Detect PS-to-PDF converter to use ...
+if command -v ps2pdf >/dev/null; then
+ ps_to_pdf_function=run_ps2pdf
+elif command -v pstopdf >/dev/null; then
+ ps_to_pdf_function=run_pstopdf
+else
man "$@"
exit $?
fi
+[[ -n "$VERBOSE" ]] && echo "Using ${ps_to_pdf_function#*_}(1) ..."
# Try to move old cache directory ...
if [[ -d "$HOME/.pdfman" && ! -d "$CACHE" ]]; then
if [[ ! -r "$PDF" ]]; then
mkdir -p "$CACHE/$SECTION"
[[ -n "$VERBOSE" ]] && echo "Converting \"$MANFILE\" to \"$PDF\" ..."
- # shellcheck disable=SC2312,SC2086
- if ! man -t "$MANFILE" | pstopdf $VERBOSE -i -o "$PDF" >/dev/null; then
+ if ! man -t "$MANFILE" | $ps_to_pdf_function "$PDF"; then
echo "Failed to convert manual page to PDF!" >&2
exit 1
fi