8.12 Advanced Printing Topics

The FreeBSD UNIX LPR/LPD printing system is very flexible, and, with the addition of filters, can be adapted to very unusual printing environments. To enhance this flexibility, several useful printing utilities are supplied on the FreeBSD CDROM which the administrator might wish to install.

8.12.1 Ghostscript

The Ghostscript program, invoked as /usr/local/bin/gs, is one of the most useful printing utilities that have been developed for the free software community. Ghostscript reads incoming PostScript data, (or Adobe PDF files) interprets it, and outputs it as a raster image. This can be displayed on screen, for example, with the GhostView program under the X Window system, or printed on most graphics printers, such as Epson dot-matrix, HP DeskJet, or HP LaserJet. In effect, it is a way of adding PostScript printing capability to a printer that doesn't have PostScript firmware code. Ghostscript has been ported to numerous operating systems including Windows.

The Ghostscript home page is located at http://www.cs.wisc.edu/~ghost/ and contains the most current version of the program. A prebuilt FreeBSD binary of Ghostscript is located in the Packages section of the FreeBSD CDROM. This can be installed on the FreeBSD system by selecting the package from the prepackaged software list that is accessed through the /stand/sysinstall installation program. Many packaged programs on the CD depend on GhostScript, and so it may already be installed.

Installation of the packaged version of GhostScript is recommended in the FreeBSD ports Section because it has been tested with the other packages that require it. The package creates a directory containing some documentation files in /usr/local/share/ghostscript/X.XX/doc. Unfortunately, because of the packaging process on the FreeBSD CDROM not all the useful installation files are copied into this location. So, if the package was version 5.03 (for example) the administrator will also want to get the file ftp://ftp.cs.wisc.edu/ghost/aladdin/gs502/ghostscript-5.02.tar.gz, and unzip and untar it into a temporary directory.

Extracting the archive file creates a directory structure under the gs5.03 subdirectory. To install ghostscript in the /etc/printcap file, read the gs5.03/devs.mak file to determine which printer driver definition works with your printer and then use the following instructions:

  1. Change to the root user with su.

  2. In the gs5.03 directory, copy the lprsetup.sh, unix-lpr.txt, and unix-lpr.sh files to /usr/local/share/ghostscript/5.03.

  3. Change to the /usr/local/share/ghostscript/5.03 directory. Edit lprsetup.sh with a text editor such as vi.

  4. Modify the DEVICES= entries to list your selected printer driver definitions per the instructions in unix-lpr.txt.

  5. Modify the PRINTERDEV= to /dev/lpt0, and the GSDIR= to /usr/local/share/ghostscript, and the SPOOLDIR= to /var/spool/output. Save the file.

  6. Edit the unix-lpr.sh file and change the PSFILTERPATH= to /usr/local/share/ghostscript.

  7. If the printer that you defined in the lprsetup.sh file is a monochrome printer, remove the "-dBitsPerPixel=${bpp}" and "$colorspec" entries on the gs invocation line and save the file. Otherwise, if it is a color definition leave them in. For example, the following line is for a monochrome LaserJet:

    ") | gs -q -dNOPAUSE -sDEVICE=${device} \"
    

    Don't remove anything else. Exit the editor, and save the unix-lpr.sh file.

  8. Copy the unix-lpr.sh file to the parent directory, /usr/local/share/ghostscript and set the execute bit on it.

  9. Set the execute bit on lprsetup.sh with chmod and run the file by typing ./lprsetup.sh.

  10. Follow the instructions on creating the Spool directories. If you will be using accounting and a separate log file, run the touch command to create the empty files per directions in script output.

  11. The sample /etc/printcap is located in the current directory; the filename is printcap.insert. Use this as a template to modify the /etc/printcap file. A sample /etc/printcap file for a LaserJet 3 is below:

    #
    #
    ljet3.raw|Raw output device ljet3 for Ghostscript:\
      :rm=big.army.mil:rp=sherman:sd=/var/spool/output/ljet3/raw:\
      :mx#0:sf:sh:rs:
    
    #
    
    ljet3|Ghostscript device ljet3 (output to ljet3.raw):\
      :lp=/dev/null:sd=/var/spool/output/ljet3:\
      :lf=/var/log/lpd-errs:mx#0:sf:sh:rs:\
      :if=/usr/local/share/ghostscript/filt/indirect/ljet3/gsif:\
      :af=/var/spool/output/ljet3/acct:
    
    #
    

8.12.2 a2ps filter

Another handy utility is the a2ps filter, short for ASCII-to-PostScript. This program takes an incoming ASCII datastream and converts it into PostScript. It can also print multiple pages on a single sheet of paper by shrinking them down. It is a useful tool for a printer that cannot interpret ASCII, such as a PostScript-only printer.

A2ps is not installed in the FreeBSD system by default; it is located in the ports section /usr/ports/print/a2ps43. A prepackaged binary can be installed with /stand/sysinstall but I have had problems with that port. It is best to install it by running make in the a2ps43 ports directory. A printcap entry and filter using this follow:

Example 8-3. /etc/printcap

#
lp|local line printer with output dumped through a2ps for raw listings:\
  :lp=/dev/lpt0:sd=/var/spool/output/lpd:lf=/var/log/lpd-errs:sh:mx#0:\
  :if=/usr/local/libexec/ascii2postscript:
#

Example 8-4. /usr/local/libexec/ascii2postscript

#!/bin/sh
#
# Simple filter that converts ASCII to PostScript for basic stuff like
# directory listings.
#

/usr/local/bin/a2ps && exit 0

exit 2

Read the system manual page for a2ps to see the options available with this program, and remember to set the filter script ascii2postscript all-executable.

This, and other documents, can be downloaded from ftp://ftp.FreeBSD.org/pub/FreeBSD/doc/.

For questions about FreeBSD, read the documentation before contacting <[email protected]>.
For questions about this documentation, e-mail <[email protected]>.