How to expand your printer's capabilities with ghostscript and apsfilter

instructions | downloads


What's the problem?

If you only ever print from Windows clients, you will probably not have any printing problems. In that case you can stop reading here.
If, however, you want to print from the command line or a script with a simple 'lpr' command, read on. Likewise, if you'd like to print to a non-PostScript printer (aka a regular PC printer) through papd, the AppleTalk print server, continue reading.

Why do I need an input filter?

To illustrate why you need an input filter, try this:
$ lpr -P%printer input.txt
where %printer is the name of a printer on your system, and "input.txt" is a Unix text file. Maybe a very old line printer will produce the desired output, but most printers will print one and a half lines of text and a lot of empty lines. For those printers you'll have to filter the input through an lpd input filter to add carriage returns and form feeds. A simple input filter would suffice for that, but you'd only be able to print Unix text files. To print other types of files, you could use specific input filters to handle those file types, or you could use a so-called magic print filter.

What's a magic print filter?

A magic print filter is a catch-all input filter with automatic file type handling capabilities. It can determine the file type of the input and decide what kind of filtering/processing is required. Most magic print filters use PostScript as an intermediate file type. PostScript is the de facto standard for printable documents and is natively supported by professional-grade printers. On Linux and other Unices it is also supported by a whole slew of utilities and converters and a very powerful piece of software called ghostscript, which enables a wide variety of devices, including many consumer-grade printers, to be used as PostScript output devices. Ghostscript effectively turns your non-PostScript printer into a PostScript printer (without actually improving the printing quality, of course).

What is apsfilter?

Apsfilter is a PostScript/ghostscript magic print filter. It is generally considered a powerful and mature print filter. It uses conversion utilities such as a2ps and pdf2ps to convert input to PostScript and uses ghostscript to print to the output device, your printer. It does all this automatically and transparently. All you need to do is issue a simple 'lpr' command, and apsfilter will take care of the rest. For example:
$ lpr -Ppingo input.txt input.pdf input.ps
will print the text file "input.txt", the PDF file "input.pdf" and the PostScript file "input.ps" to the printer "pingo".
These three input types, text, PDF, and PostScript, are the file types that you'll be able to print if you follow the installation instructions below. For any other file types you'll need to install additional PostScript converters, such as html2ps to print HTML files from the command line, or rtf2ps to print RTF files. These converters require that you install quite a few additional libraries, though, and printing HTML and RTF files from the command line is not our aim. Our aim is to print PostScript print jobs to a non-PostScript printer transparently, i.e. with a simple 'lpr' command.

How is this related to papd, the AppleTalk print server?

The standard print command for papd in SME Linux is "lpr -P%printer input". With apsfilter and ghostscript installed, this print command will take PostScript input and will output to any printer supported by ghostscript.
Papd registers all printers in the system as PostScript printers. This means that AppleTalk clients see all printers as PostScript printers. The PostScript driver on the AppleTalk client will convert print jobs to PostScript and the client will send it to papd. With apsfilter and ghostscript installed, the papd printer will be able to print these PostScript print jobs even if the printer is a non-PostScript printer.

Does this affect Windows printing?

Apsfilter does not interfere with Windows printing. The print command for Samba, the Windows print server, is "lpr -b -P%printer input". The "-b" option instructs lpr to bypass all filter processing. Samba simply passes the print jobs that it receives from Windows clients on to the print spooler. It relies on the printer drivers installed on the Windows clients to provide print jobs in a format that is understood by the printer.

Installation instructions for ghostscript and apsfilter

  1. If you added a printer through the server-manager, first remove it again through the server-manager. We need to do this because the apsfilter setup script tries to be as non-destructive as possible and will not let you add an apsfilter configuration to an existing printer. If you don't remove the existing printer configuration, you will need to change the apsfilter configuration to point to the correct printer after running the apsfilter setup script.
  2. Download and install the following RPMS for your particular architecture (alpha or i386) and version: Links to these files are below.
  3. Run the apsfilter setup script (as root):
    # /usr/share/apsfilter/SETUP
    Answer all questions. The script gives a strange warning about having found an existing apsfilter configuration in /etc/printcap, and asks whether you wish to add a new configuration or overwrite the existing one. Either is fine: we will make our own changes to /etc/printcap anyway. The central page in the setup script looks like this:

    	==================================================================
    	  A P S F I L T E R   S E T U P                   -- MAIN MENUE --
    	==================================================================
    
    	(D)	Available Device Drivers in your gs binary
    	(R)	Read Ghostscript driver documentation        (devices.txt)
    
    	(1)	Printer Driver Selection                []
    	(2)	Interface Setup                         []
    	(3)	Paper Format                            []
    	(4)	Printing Quality                        [medium]
    	(5)	Color Mode                              [full]
    	(6)	Print Resolution in "dots per inch"     [300x300]
    	(7)	Default Printing Method                 [auto]
    
    	(A)	Abort installation (don't do anything)
    	(Q)	==> Finish installation
    
    	Your choice?
    

    You should go through steps 1 through 7 in order. The first page for step 1 looks like this:
    	================================================================
    			PRINTER DRIVER SELECTION
    	================================================================
    	Please select the type of printer you want to install:
    
    	1)  PostScript printer (generic)
    	2)  PostScript printer (with ghostscript drivers)
    	3)  printer driver natively supported by ghostscript
    	4)  gimp-print / stp
    	5)  hpdj
    	6)  pcl3 (successor to hpdj)
    	7)  IBM Omni
    	8)  various HP Deskjet drivers
    	9)  PPA printer
    	10) official HP DeskJet drivers (hpijs 0.97)
    	11) official HP DeskJet drivers (hpijs 1.0)
    	12) Epson printer (official drivers)
    	13) Lexmark inkjet printer
    	14) miscellaneous other drivers
    	15) non-printer devices (caution! -- read the handbook)
    
    	0)  return to main menu
    
    	Your choice:
    

    Please note that options 4 through 14 will not work with the minimal ghostscript RPM. Therefore, if you have a non-PostScript printer, your only choice here is option 3. But, on the upside, a very large number of printers are natively supported by ghostscript.
    Once you've gone through steps 1 through 7, the main menu will look similar to this:

    	==================================================================
    	  A P S F I L T E R   S E T U P                   -- MAIN MENUE --
    	==================================================================
    
    	(D)	Available Device Drivers in your gs binary
    	(R)	Read Ghostscript driver documentation        (devices.txt)
    
    	(1)	Printer Driver Selection                [deskjet]
    	(2)	Interface Setup                         [parallel]
    	(3)	Paper Format                            [a4]
    	(4)	Printing Quality                        [medium]
    	(5)	Color Mode                              [full]
    	(6)	Print Resolution in "dots per inch"     [300x300]
    	(7)	Default Printing Method                 [auto]
    
    	(T)	Print Test Page
    	(V)	View performance log (times of print attempts)
    	(A)	Abort installation (don't do anything)
    	(I)	==> Install printer with values shown above - repeat this
    		    step for installing multiple printers
    	(Q)	==> Finish installation
    
    	Your choice?
    

    You may print a test page (T) and, if you're pleased with the result, install the printer (I).
    Choosing to install the printer will bring up the following page:

    	Please enter a printer queue name for printer 'deskjet'. The
    	default name is 'lp'.
    
    	Your choice:
    
    

    Enter the name that you want to use for your printer. This name should be lower-case only. After finishing the apsfilter configuration, you will add the printer to the SME configuration by the name you enter here, so the name you enter here will be the printer's real name and not just a temporary name.
    After entering the printer name, you're back in the main menu. Choose Q to finish installation.
  4. Next, make a custom-template fragment for /etc/printcap and add a line for the input filter:
    # mkdir -p /etc/e-smith/templates-custom/etc/printcap
    # cp /etc/e-smith/templates/etc/printcap/05printer \
    /etc/e-smith/templates-custom/etc/printcap/

    Use your favorite editor to edit the file /etc/e-smith/templates-custom/etc/printcap/05printer and add a line for the input filter. When you're done with it, it should look something like this (without the 'add--->' bits, obviously):

    {
        use esmith::db
    
        # process all accounts
    
        my %accounts;
        tie %accounts, 'esmith::config', '/home/e-smith/accounts';
    
        my @printers = grep { db_get_type(\%accounts, $_) eq 'printer' }
    			keys %accounts;
        $OUT = "";
    
        foreach my $printer ( @printers )
        {
            $OUT .= "\n";
            $OUT .= $printer;
            $OUT .= "|" . db_get_prop(\%accounts, $printer, 'Description') . ":\\\n";
            $OUT .= "\t:server:\\\n";
            $OUT .= "\t:mx#0:\\\n";
            $OUT .= "\t:sh:\\\n";
            $OUT .= "\t:ff_separator=false:\\\n";
            $OUT .= "\t:sd=/var/spool/lpd/$printer:\\\n";
    add---> #begin apsfilter
    add---> $OUT .= "\t:if=/etc/apsfilter/basedir/bin/apsfilter:\\\n";
    add---> #end apsfilter
    
            if (db_get_prop(\%accounts, $printer, 'Location') eq 'remote')
            {
    	    $OUT .= "\t:rm=" . db_get_prop(\%accounts, $printer, 'Address') . ":\\\n";
    
    	    # no trailing backslash for last entry
    
    	    if (db_get_prop(\%accounts, $printer, 'RemoteName'))
    	    {
    	        $OUT .= "\t:rp=" . db_get_prop(\%accounts, $printer, 'RemoteName') . ":\n";
    	    }
    	    else
    	    {
    	        $OUT .= "\t:rp=raw:\n";
    	    }
            }
            else
            {
    	    # no trailing backslash for last entry
    	    $OUT .= "\t:lp=/dev/" . db_get_prop(\%accounts, $printer, 'Location') . ":\n";
            }
        }
    
    }
    
  5. Next, use the printer panel in the server-manager to add a printer with the exact same name as you've just configured in the apsfilter setup script. This will add the printer to the Samba and AppleTalk configurations, so that it becomes visible to client machines.

Client-side configuration

MacOS

Open the Chooser, select 'LaserWriter 8'. Your printer should now show up as a 'PostScript Printer'. Set it up as a 'Generic' PostScript printer.

SME Server

The command to print files from the SME Server is "lpr -P%printer". So, if you named your printer "pingo", the command would be "lpr -Ppingo". You can set this command as the default printer in pine or add this command as a local printer in /etc/lynx.cfg.

Known problems

Downloads: RPMS you need to install

alpha i386
ghostscript-6.51-16es2.alpha.rpm ghostscript-6.51-16es2.i386.rpm
ghostscript-fonts-5.50-3.noarch.rpm ghostscript-fonts-5.50-3.noarch.rpm
urw-fonts-2.0-12es2.noarch.rpm urw-fonts-2.0-12es2.noarch.rpm
apsfilter-7.2.5-1rvda.noarch.rpm apsfilter-7.2.5-1rvda.noarch.rpm
SME/Alpha V5.5 5.0/5.1 5.5 5.6
a2ps-4.13b-15.alpha.rpm a2ps a2ps a2ps
psutils-1.17-13.alpha.rpm psutils psutils psutils
Package sources
apsfilter-7.2.5-1rvda.src.rpm
The other sources can be found in Charlie Brady's contrib area and on RedHat's ftp servers.

Robert van den Aker. Last modified: Mon, Feb 17 2003.