Unix Printing Basics
Pages: 1, 2
Check Your Hardware
Once you have Ghostscript and any necessary drivers installed, double-check that your FreeBSD system sees your printer. The FreeBSD handbook has explicit instructions for testing a printer connected to a parallel or serial port. However, my printer uses a USB interface. Since USB is hot swappable, I can plug my printer into an available USB port without having to first shutdown the system. As soon as I make the connection, my console (Alt F1) shows this message:
ulpt0: Hewlett-Packard officejet 4100 series, rev 2.00/1.00, addr 2, iclass 7/1 ulpt0: using bi-directional mode
Which is an encouraging sign.
Note: If your message instead shows
ugen0 (the generic USB
driver) message, you probably removed
ulpt support from your
kernel configuration file. Rebuild your kernel with
Choosing a Configuration Tool
How you proceed is a matter of personal preference. My favorite
configuration utility is
/usr/ports/print/apsfilter, as it provides
an easy-to-use, lightweight text interface. Michael Lucas wrote a
detailed tutorial on using Apsfilter.
If your recommended driver is compiled into Ghostscript, you'll find
configuring and testing your printer a breeze with Apsfilter. It will
automagically create the correct entries in
How do you find out if Ghostscript includes your driver? Once you've
installed Ghostscript, type
gs -h. You'll receive a page of
output, so you may want to
grep for your particular driver name.
In my case, searching for
hpijs will fail but searching for
ijs will succeed.
Unfortunately, Apsfilter isn't the best approach for this particular printer. My recommended driver is an add-on to Ghostscript and Apsfilter is a script that lets you choose from the drivers compiled into Ghostscript. It would take a lot of trial and error on my part to find the closest driver in that list. I'm not really into a lot of trial and error. Besides, I want to take full advantage of the correct driver.
Instead, I'll take a look at what came with that
hpijs port I
# more /usr/ports/print/hpijs/pkg-plist bin/hpijs %%PORTDOCS%%%%DOCSDIR%%/gs_hpijs.png %%PORTDOCS%%%%DOCSDIR%%/hpijs_readme.html %%PORTDOCS%%@dirrm share/doc/hpijs
That's not much to work with, a binary without a man page and a
assumes I'm installing using CUPS. (I'll discuss CUPS in greater detail in the
next article). Since I don't want the overhead of CUPS for a local printer,
I'll try a different approach. Since I didn't include the
directive in my
make install command when I built the
hpijs port, I still have its working directory:
# ls /usr/ports/print/hpijs/work
Bingo! I've hit pay dirt. This directory contains the
foomatic-rip script as well as a directory of PPDs that includes a PPD for my particular model of printer.
What exactly is
foomatic-rip? It is a foomatic
script that understands a database of all known printer drivers, even those not
compiled into Ghostscript.
While it may seem counterintuitive, it looks like my easiest course of
action is to edit
/etc/printcap manually, telling it to use
foomatic-rip and my printer's PPD file.
First, I'll need to copy those files from the work directory to more
reasonable locations. I'll place
foomatic-rip in the directory that contains programs installed by ports, and the PPD into a subdirectory of
# cd /usr/ports/print/hpijs/work/hpijs-1.5 # cp foomatic-rip /usr/local/bin/ # mkdir /etc/foomatic # cp ppd/HP-OfficeJet_4110-hpijs.ppd /etc/foomatic/
Next, I'll create a spooling directory called
to hold the print jobs sent to my OfficeJet printer:
# mkdir /var/spool/lpd/OfficeJet
Now, I'm ready to add the following lines to
lp|OfficeJet:\ :lp=/dev/ulpt0:\ :af=/etc/foomatic/HP-OfficeJet_4110-hpijs.ppd:\ :if=/usr/local/bin/foomatic-rip:\ :sd=/var/spool/lpd/OfficeJet:\ :sh:
Even if you don't have to create your
manually, it's important to understand the contents of this file so that you
can troubleshoot your printing system.
man printcap will always
show you the meanings of the various capabilities (for example,
sd). Let's pick apart this
The default printer is always
lp. It can have as many nicknames
as you want to give it, as long as you separate them with the pipe character
|). Here, I've given the nickname
that every line in this file (except for the very last one) ends with
:\ and every line (except the very first one) begins with
:lp in the second line refers to the physical device where the
printer attaches. Since mine is a USB printer, it uses
:af gives the full path to the accounting or PPD file.
:if gives the full path to the input filter. Here, I use
foomatic-rip. If you instead use
apsfilter, the entry
it creates for you will refer to
:sd gives the full path to the spooling directory.
:sh stands for suppress header, so the spooler will not create
a header page with the print job.
Creating a Test Page
Once I've finished configuring
/etc/printcap, I need to tell
lpd that its configuration file has changed:
# /etc/rc.d/lpd restart
I'm now ready to try printing a test page. From the command line as a regular user, I'll ask for a print out of my printer configuration file:
% lpr /etc/printcap
Excellent, my printer starts to make printing noises. My console (Alt F1) also gives messages showing that foomatic-rip is doing its thing.
For my next test, I start an X session where I'm using KDE as the window manager. I open up the Firefox browser, click on the File menu -> Print Preview, and see that this function works. I then successfully print a web page from my browser.
I next try to print a specified page from an OpenOffice document. Again,
success. See how the various programs on a system all rely on a properly
/etc/printcap file? With this file setup correctly,
you should be able to print from any application.
In the next article, I'll experiment with that
application. I'll also discuss CUPS and demonstrate its usage.
Dru Lavigne is a network and systems administrator, IT instructor, author and international speaker. She has over a decade of experience administering and teaching Netware, Microsoft, Cisco, Checkpoint, SCO, Solaris, Linux, and BSD systems. A prolific author, she pens the popular FreeBSD Basics column for O'Reilly and is author of BSD Hacks and The Best of FreeBSD Basics.
Read more FreeBSD Basics columns.