Skip to content

Instantly share code, notes, and snippets.

@mulle-nat
Last active June 6, 2022 16:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mulle-nat/099fb09380cf25744dc7b9ecf09a0e37 to your computer and use it in GitHub Desktop.
Save mulle-nat/099fb09380cf25744dc7b9ecf09a0e37 to your computer and use it in GitHub Desktop.
mulle-printpdf - print a PDF file on a PostScript Network Printer
#!/bin/sh
#
# Print PDF to a PostScript capable network printer
#
PRINTER="${PRINTER:-brother.local}"
PRINTER_PORT="${PRINTER_PORT:-9100}"
if [ $# -eq 0 -o "$1" = '-h' -o "$1" = "--help" ]
then
cat <<EOF >&2
Usage:
mulle-printpdf [options] <pdffile>
Print a PDF file on a PostScript capable network printer.
Options will be passed to pdftops(1).
This script uses an **unencrypted** network connection!
Environment:
PRINTER : Printer network address (${PRINTER})
PRINTER_PORT : Printer port (${PRINTER_PORT})
Dependencies:
uuidgen (apt:uuid-runtime), netcat, pdftops
EOF
exit 1
fi
#
# pdftops works better than pdf2ps for me, as my brother laserprinter
# croaks on pdf2ps output
#
uuid="`uuidgen 2> /dev/null`" # no problem if not installed
psfile="/tmp/printer-${uuid:-${LOGNAME}}.ps"
finish()
{
rm -f "${psfile}" 2> /dev/null
}
trap finish EXIT
pdftops "$@" "${psfile}" || exit 1
#
# tell netcat to close after sending file with -N
#
netcat -N "${PRINTER:-printer}" "${PRINTER_PORT}" < "${psfile}" || exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment