Last active
June 6, 2022 16:48
-
-
Save mulle-nat/099fb09380cf25744dc7b9ecf09a0e37 to your computer and use it in GitHub Desktop.
mulle-printpdf - print a PDF file on a PostScript Network Printer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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