Home Networking With HALNet ADSL
Home       Print this page
Printing with LPR

     LPR (Line Printer) is the standard in printing with BSD based UNIX and most Linux systems (even though most Linux distributions are based on SVR4). It is a fairly universal way to print even though it originated in the daisy wheel and dot matrix era. Most cable/dsl routers that have a print server built-in use this same protocol to print with, so even if you're not using any UNIX variant it may still be beneficial to learn more about how it works.
     The LPR service is made up of the lpd(8) daemon, a spool directory (normally /var/spool/lpd/printer that's owned by the user and group "daemon" and chmod 770), a configuration file (/etc/printcap), and a filtering script (normally in /usr/libexec or /usr/local/libexec that's chmod ugo+x).
     The following is an example of my printcap for my HP LaserJet III that is attached to "Beastie" (p133 running FreeBSD 4.7):
lp|ljiii|HP LaserJet III:\
:sh:\
:sd=/var/spool/lp0:\
:lp=/dev/lpt0:\
:if=/usr/local/libexec/hpif:\
:lf=/var/log/lp0.log:
     Each variable is to be separated by a ':' and must be in one continuous line. The '\' at the end of each line allows you to break it up for easier reading. The first line is for the printer name(s). The "lp" makes it a default printer (just like Windows has), each of the other names are just free form descriptors and have to be separated by a pipe ( | ), the 'sh' being left blank turns off the header page, the 'sd' is the spool directory, the 'lp' is the printer port, and the 'if' is the script that the document is filtered through. The ONLY line that should be touching the left margin is the printer name.
     You MUST have Ghostscript installed in order to use the following script. Most major UN*X like opperating systems either have it preinstalled or make it available in an easily installed package of some kind. The following is an example of my "hpif" script used on my HP LaserJet III:
#!/bin/sh
# This converts Line Feeds into Line Feed/Carriage Return.
# Without it you would end up with a staircase effect.
printf "\033&k2G" || exit 2
read first_line
first_two_chars=`expr "$first_line" : '\(..\)'`

# Is it Post Script? if [ "$first_two_chars" = "%!" ]; then
exec 3>&1 1>&2
/usr/local/bin/gs -dSAFER -dNOPAUSE -q -sDEVICE=laserjet \
-sOutputFile=/dev/fd/3 - && exit 0

/usr/local/bin/gs -dSAFER -dNOPAUSE -q -sDEVICE=laserjet \
-sOutputFile=- - && exit 0
else
# Print a Form Feed at the end echo $first_line && cat && printf "\033&l0H" &&
exit 0
fi
exit 2
     If you own an HP printer then you're in luck. HP actually makes and supports UN*X print drivers. More information on printing to HP printers can be found at the HP Linux Driver Project page. There is no shortage of example printer scripts on the internet if you don't have an HP, so it shouldn't be too hard to find one that will work with your printer. All it should take is a few minutes and a Google search. You can find out more about LPR in the FreeBSD Handbook.
     You MUST have a list of computers that you would like to allow access to your printer. On the print server, enter their ip addresses or names in /etc/hosts.lpd. Each computer must be listed on a separate line.
     There is a VERY useful program made by IBM called LPR Remote Printing Client. It allows Windows 95/98/ME machines to print to an LPR printer. Windows NT, XP, and 2K even have support for UNIX based printers built into the OS! The XP and 2K LPR client can be installed from:
Control Panel ->
Add/Remove Programs ->
Add/Remove Windows Components ->
Other Network File and Print Services
     NOTE: Since most every UN*X print server uses Post Script you should try to select a Post Script driver for your printer (ex. "HP LaserJetIII PS" instead of "HP LaserJetIII"). This doesn't always work for all printers so try it first, then try the regular driver.

     Now that you have the print server configured you can set up your clients. If you are using the IBM LPR program to print from a Windows box then please read the documentation provided on their page.
     Printing from UN*X to UN*X across a network is very similar to printing to a local printer. The only difference between the two is that you don't have us use a filter script (the server does that for you) and the printcap (/etc/printcap) is a little different.
     The following is an example of the printcap file on my laptop (pII/333 running FreeBSD
4.7): rljiii|HP Laserjet III on Beastie:\
:sh:\
:lp=:\
:rm=beastie:\
:sd=/var/spool/lpd/rljiii:\
:lf=/var/log/rljiii.log:

lp|rlj4|HP Laserjet 4 on router:\
:sh:\
:lp=:\
:rm=192.168.0.1:sd=/var/spool/lpd/rlj4:lf=/var/log/rlj4.log:\
:if=/usr/local/libexec/if-lj4:
     The first section is for printing to my LaserJet III at home. "Beastie", my print server, is already configured with a filtering script, so I don't need have one on my laptop in order to print to that one (no "if" statement). Since I use my laptop primarily from HAL I have my local LaserJet 4 set as my default printer (note the "lp" at the beginning). It is connected to a dsl router that has a built-in LPR server (make sure its truly LPR if you get one), however the router does not have any filtering or conversion capabilities and the printer cannot print Postscript, so I had to create a special script for the printer.
#!/bin/sh
printf "\033&k2G" || exit 2
read first_line
first_two_chars=`expr "$first_line" : '\(..\)'`

if [ "$first_two_chars" = "%!" ]; then
exec 3>&1 1>&2
/usr/local/bin/gs -dSAFER -dNOPAUSE -q -r600 -sDEVICE=ljet4 \
-sOutputFile=/dev/fd/3 - && exit 0
/usr/local/bin/gs -dSAFER -dNOPAUSE -q -r600 -sDEVICE=ljet4 \ -sOutputFile=- - && exit 0
else
echo $first_line && cat && printf "\033&l0H" && exit 0
fi
exit 2

     The filter I'm using is almost the same as the one on my print server at home. The only differences between the two are the driver ("-sDEVICE=ljet4") that gs(1) uses (find a driver name for your printer with "gs -h") and the resolution that it prints at (default is 300dpi but I set this one to 600 with the "-r600" flag).

     Keep in mind that you get what you pay for, or more accurately "you don't get what you don't pay for". This D-Link router/printserver tends to choke on large print jobs and makes each page an effort (10 second delay between pages), where as my little recycled p133 at home hasn't hiccuped once. I have yet to find a router/printserver combo with the same quality LPR as the old stand-alone 1 or 2 port HP JetDirect print servers. If you find one, then please let me know. I'd like to have something nice to say about a cable/dsl router.



     NOTE: Do some research before investing in a router/printserver combo unit. There are some that use only proprietary Windows drivers. Its still a scary idea even if you're using nothing but Windows.


     UPDATE: I've since given up on the router/print server combo and set up a REAL router/print server (please see my FreeBSD router HOW-TO for more information). Life is too short to jack with things that don't work "as advertised".

Join HAL-PC
http://www.hal-pc.org
4543 Post Oak Place Dr. Suite 200
Houston, Tx 77027-3103
713/993-3300



This site is designed to be of some assistance, however is not meant to be your sole source of information. By following the suggestions given on this page you understand that you do these things at your own risk. The steps mentioned here may or may not work for your purposes. There is no warranty or support of any kind provided by HAL-PC for the topics discussed in this site. The only support for your home network that is given is by me personally, at my choosing, on my own time, and via email only.
I know... I hate disclaimers too.

[Powered by FreeBSD]