Brother HL-2040, Ghostscript, and lpr

and udev and Slackware linux

Why do I insist on using old lpr instead of CUPS? I don't know. Call it stubborn adherence to tradition. So I use lpr. These instructions are for lpr! If you want CUPS, these instructions are not for you. But you might find something in the resources links, below.

In any case, I plugged in my Brother HL-2040 printer, and (assuming you have a USB kernel with USB printer support) got myself a brand new /dev/usb/lp0 device. I had udev make me a /dev/lp symlink for that device whenever it came online (see Writing udev Rules for info on how to do this.)

So with that in mind, it was time to add a couple print filters, one for PostScript and one for ASCII text. Now, if you don't want to do this part, check out apsfilter for another way, and ignore all of what I say about filter scripts and /etc/printcap--and since that's all I talk about for the rest of the document, it means you're pretty much done with me at this point.

But if you want to roll your own the "hard" way, keep on reading...

File "lppsfilter", to be placed somewhere in the path like /usr/local/bin... this assumes a working Ghostscript install (which should come standard with most linux distros)...

#!/bin/sh

# lppsfilter for doing postscript conversion
gs -r600 -q -dNOPAUSE -sDEVICE=hl1250 -sOutputFile=- -

File "lpasciifilter", to be placed somewhere in the path like /usr/local/bin... this assumes a working Ghostscript install and a working a2ps install (both of which should come standard with most linux distros)...

#!/bin/sh

# lpasciifilter for doing ASCII conversion
a2ps -1 -B --borders=off -o - | gs -r600 -q -dNOPAUSE -sDEVICE=hl1250 -sOutputFile=- -

a2ps has all kinds of nifty features like 2 pages per page, 4 pages per page, landscape output, borders, etc., etc. I turned all that stuff off in the above example. You can add more filters with the appropriate flags, and then add a new "virtual" printer to your /etc/printcap, below, to use that filter. You can even use it to put multiple PostScript pages on a single sheet, I think--I haven't tried it, but it looks like it would work.

The "-r600" switch to Ghostscript is very important with the HL-2040 printer...otherwise you'll get a page that looks split in half with duplicate data in right and left columns. Very ugly and wrong. And then after cursing everyone on the internet who says it works great out of the box and chewing through a number of test pages, you'll finally learn to ignore the pain in your teeth from your encounter with the dentist earlier in the day and realize that obviously it's some kind of resolution problem and force the resolution to 600dpi just like a lot of pages say to do, and then you'll decide to spare everyone else the trouble and write up a web page of your own to describe in detail the chain of events that led to the HL-2040 becoming a functioning printer under Slackware Linux.

Breath.

Where was I... Oh yeah. Ok, so we have /dev/lp pointing to the printer device thanks to the udev magic, and we have a couple print filters saved off that we can use. Time to set up /etc/printcap. (Note: if you didn't set up the /dev/lp symlink earlier, you can probably just refer to the printer by the name /dev/usb/lp0 in your printcap file. Unless you have more than one printer, or it's not USB.)

lp:sd=/var/spool/lpd:lp=/dev/lp:if=/usr/local/bin/lpasciifilter
ps:sd=/var/spool/lpd:lp=/dev/lp:if=/usr/local/bin/lppsfilter

The first line is the default printer, named "lp", that prints ASCII text. If you want to print PostScript by default, put the "ps" printer line first. You probably do that the PostScript to be default, otherwise you'll find you're printing pages of PostScript as ASCII text. Unless, like some people, you print more ASCII text than PostScript.

To use:

$ lpr -Pps foo.ps   # <-- prints a PostScript file on printer "ps"
$ lpr -Plp bar.txt  # <-- prints a text file on printer "lp"
$ lpr frotz.txt     # <-- prints to default printer

Final note to Slackware lpr fans--all the utils like lpr, lpq, and lprm are symlinked to the CUPS versions, so you'll have to change those over.

Resources


Questions about or improvements to this page? Write beej@beej.us!