Nat! bio photo

Nat!

Senior Mull

Twitter Github Twitch

Printing PDFs with the Brother HL4150 CDN on Linux

My Brother HL4150 CDN is a network connected, PostScript capable Laserprinter. How hard can it be to get a print out ?

Well… Unfortunately the LPR/CUPS drivers are eleven years old. So the install packages are 32 bit only. Without any drivers installed, the printer chokes on any input with the cryptic error message:

Unrecoverable error: rangecheck in .putdeviceprops
                                                  Operand stack:
                                                                    true

I have to admit, the last time I had to print something on the old machine, I actually spent too much time, installing i386 comaptibility libraries, building the open-sourced driver and searching around for compatible PPDs.

I did not want to do this again on the new machine.

Luckily printing is actually fairly simple. You connect to a socket, send over your file and close the socket. As the printer maintains its own printing queue. There is no need for me to buffer anything on the client.

So I use pdftops to convert the PDF to PostScript. And then I send the file to the printer with netcat.

pdftops foo.pdf foo.ps
netcat -N brother.local 9100 < foo.ps

And wrrrrrrrm, I get a nice printout.


I made myself a shell script, which cleans up the temporary PostScript file:

mulle-pdf

#!/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 (brother.local)
   PRINTER_PORT : Printer port (9100)
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`" # 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

Post a comment

All comments are held for moderation; basic HTML formatting accepted.

Name:
E-mail: (not published)
Website: