Nat! bio photo


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:

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
netcat -N brother.local 9100 <

And wrrrrrrrm, I get a nice printout.

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


# Print PDF to a PostScript capable network printer


if [ $# -eq 0 -o "$1" = '-h' -o "$1" = "--help" ]
   cat <<EOF >&2
   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!
   PRINTER      : Printer network address (brother.local)
   PRINTER_PORT : Printer port (9100)
   uuidgen (apt:uuid-runtime), netcat, pdftops
   exit 1

# pdftops works better than pdf2ps for me, as my brother laserprinter
# croaks on pdf2ps output
uuid="`uuidgen`" # no problem if not installed

   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.

E-mail: (not published)