![]() | ![]() | ![]() | ![]() |
|
faq search add article cool-stuff how-to main tips |
Posted by Jason on Monday September 03, @01:04PMfrom the spit-it-out dept. Printing in UNIX whether it's FreeBSD or some other flavor can be a real pain. Here is a guide that will help you configure printing on your system using the Ghostscript utility. [Background Info] Back in the 80's when I was running AT&T 286 Unix (it rocked! (grin)) you had laser printers with postscript and you had dot matrix character printers - that was basically it. There were no drivers to install and printing was pretty basic. These days things have not really changed all that much. The difference is that now you can install a utility that can convert postscript to pcl or some other type of printer language by using an input filter. The conversion occurs with this really great program called Ghostscript. Using a small shell script called from your printcap file, you can examine the headers of a file and determine if it is postscript or plain text. If it is postscript, ghostscript pre-processes and converts it to something your printer understands such as pcl prior to sending to the printer. Ghostscript supports most popular printers such as HP, Canon, Epson and others. I currently use it to print to an HP LasterJet III, and in the past I have used it to print to a Canon bj200e. note: most of the programs you run in X print in postscript format by default. Examples of these are Netscape, The Gimp, Adobe Acrobat and many others. This makes the ghostscript utility an invaluable tool. There are four steps you need to perform in order to configure printing in this manner: 1 - Install Ghostscript 2 - Modify /etc/printcap and create a queue 3 - Create an input filter 4 - Start the line printer daemon [1 - Install Ghostscript] You will find ghostscript in the ports tree under /usr/ports/print/ghostcript55. Here is how to install it. Login: root Password: ******** cd /usr/ports/print/ghostscript55 make install && make clean After the install of ghostscript, you can verify what printers are supported by typing gs -? or by checking the docs in /usr/local/share/ghostscript5.50/doc. If you are not familiar with installing programs in FreeBSD, you can read this how-to for assistance. [2 - Modify printcap and create a queue] After installing ghostscript, you need to modify your /etc/printcap file. The printcap file defines information such as the name of your printer, what print queue to use, what input filter to use, and where to log any errors that may occur. You also need to create a spool directory where your print jobs will be queued. You can use your favorite editor to create/modify the printcap file. I typically use ee, but many people prefer to use vi. Be sure to login as root. cd /etc ee printcap Here is what I have in my /etc/printcap file: # /etc/printcap lp|hplj3:\ :sh:\ :lp=/dev/lpt0:\ :sd=/var/spool/lpd/hplj3:\ :mx#0:\ :lf=/var/log/lpd-errs:\ :if=/usr/local/libexec/hpif: Here is a breakdown of the switches in my printcap file: lp and hplj3 -> what I have named my printer (two names) sh -> disables a banner from printing lp -> my parallel printer (lpt1) sd -> my spool directory mx -> max file size (o=unlimited) lf -> error file if -> input filter (runs ghostscript) Creating the print queue or spool directory as it is commonly referred to is easy. Login as root and issue the mkdir command. mkdir /var/spool/lpd/hplj3 [3 - Create an input filter] To use this script with your printer, you should modify the two instances of -sDEVICE=ljet3 replacing ljet3 with the name of the driver that matches your printers model number. To find out what printers are supported by ghostscipt and their corresponding device names, you can issue the command gs - ? and/or read the documentation located in /usr/local/share/ghostscript/5.50/doc. Here is what I have in my hpif file. #!/bin/sh # # hpif - Print Ghostscript-simulated PostScript on a HP Laserjet III # Installed in /usr/local/libexec/hpif # # Treat LF as CR+LF: # printf "\033&k2G" || exit 2 # # Read first two characters of the file # read first_line first_two_chars=`expr "$first_line" : '\(..\)'` # if [ "$first_two_chars" = "%!" ]; then # It is PostScript; use Ghostscript to scan-convert and print it. exec 3>&1 1>&2 /usr/local/bin/gs -dSAFER -dNOPAUSE -q -sDEVICE=ljet3 \ -sOutputFile=/dev/fd/3 - && exit 0 /usr/local/bin/gs -dSAFER -dNOPAUSE -q -sDEVICE=ljet3 -sOutputFile=- - \ && exit 0 else # Plain text or HP/PCL, so just print it directly; print a form # at the end to eject the last page. # echo $first_line && cat && printf "\033&l0H" && exit 0 fi exit 2 As you may have noticed from the printcap file, the filter script hpif should be stored in /usr/local/libexec. [4 - Start the line printer daemon] You have to start the line printer daemon so it can listen for incoming print jobs and process them. You can start the line printer daemon by logging in as root and typing: lpd To start the daemon every time FreeBSD starts add the line lpd_enable="YES" to your /etc/rc.conf file. Again, you can use ee or vi for this. Assuming you have done everything correctly, you should now be able to print ascii text and postscript print jobs to your non-postscript printer. Try a text file by issuing the command: lpr -P {your printer name from printcap} somefile.txt You can try a postscript job by printing from Netscape. When you select print from within Netscape there will be a command line asking what the print command is. You should type something like this: lpr -P {your printer name from printcap} That's about all there is to it. However, I recommend that you read the man pages of some of the more common printer command line utilities: man printcap man lpd man lpr man lpq man lprm To download a copy of the printcap and hpif filter file used in this How-To, click on the link titled printfiles.tar located in the upper right sidebar of this page. The two files are in tar format. If you unfamiliar with the tar command, please read this how-to to learn more about it. < | >
|
|
|||||||||||||||||||||||||
|
|||||||||||||||||||||||||||
| "You never know how many friends you have until you own a Condo on the beach." -- Jason's Postulate |
|
| All trademarks and copyrights on this page are owned by their respective companies. Comments are owned by the Poster. The Rest ©2001 Jason Neumann. |