Solaris print filters for postscript files

Contents:

What are we talking about?

As UNIX-like systems become more prevalent in this world of cheap computing, more and more users will be faced with the fact that UNIX tools speak postscript when they want to print. In addition, anyone doing research in advanced computer topics will find that postscript is the format of choice (far above and beyond that of M$ Word and PDF). SO, if you have a printer that does not understand postscript, which is likely unless you own an expensive printer, you need to figure out how to print as easily as possible. Most likely you have discovered that ghostscript will convert to something that personal printers understand (PCLn on HP printers for example).

Since you can use ghostscript to convert the postscript to a usable format, the next step is to make it as convenient as possible to do so. Solaris has the capability to configure print filters that will automatically convert file formats to make the print job input format equivalent to one that the printer understands.


How it works

In practice this is how Solaris print filters work:

  1. User submits print job using the lp mechanism
  2. Solaris examines the file type (as file(1) would, presumably)
  3. Solaris compares this to the types of files that the physical printer accepts
  4. If they do not match, it tries to use any combination of registered print filters to obtain the correct format
A print filter is basically a mechanism that has an input type (postscript for example), an output type (PCL) and the command to run to accomplish this transformation. Usually the input and output will be sent through pipes. So, you would setup the command to run ghostscript with whatever flags are necessary plus the flags to indicate that the input is coming from stdin and the output is going to stdout

The print filter is basically a file in a format that Solaris understands. In this you indicate the input/output types, the command and other options. This file is then presented to the OS using the lpfilter(1M) command, at which time it will be a possible filter for any new print jobs. It is possible to restrict the filter so that it is only used by certain printers on the system.


Requirements

To convert postscript to another format you will need ghostscript installed. This procedure has been tested on Solaris 2.5.1 and 2.6, so it will probably work on 2.4 or greater, and maybe even 2.x. Ghostscript must support an output type that your printer understands.

Configuring Solaris

First you need to create a print filter file. You can copy an existing one from the files in /etc/lp/fd/. Here is the the one I use to do straight postscript-to-PCL conversion (PCL is what HP printers understand):
ps2pcl.fd
Input types: postscript
Output types: PCL5
Printer types: any
Printers: nuts
Filter type: slow
Command: /usr/local/bin/gs -q -dSAFER -dNO_PAUSE -sDEVICE=ljet4 -r600 -sOutputFile=- -

See the ghostscript documentation to decide which flags are correct for you. Notice the the output file is ``-'', which is stdout and the input (last parameter) is also ``-'', which is stdin. The input type (first line) is a string that Solaris uses, postscript and simple are the only ones that are probably useful; simple being plain text. The input type may somehow correspond to the types that the file(1) command spits out, but I have not verified this. The output type is arbitrary and is used to match the type that you say the physical printer can understand; we will discuss this below. You can restrict the filter to be used only on certain print queues using the ``Printers'' line. I am not sure what effect the ``Filter type'' has, but running a program like ghostscript to do the work is definitely slow!

Next, you need to register this print filter with the OS. Using the lpfilter(1m) command, we register it and assign it a name as follows:

# lpfilter -f ps2pcl -F /etc/lp/fd/ps2pcl.fd
The first flag (-f) and its parameter tell the filtering system the name that we want to use to refer to this specific filter in the future. The second flag (-F) is the file which contains the print filter information; this is the file that you have just created. The print filter is now registered. You need to rerun this command if you make any changes that you make to the filter file.

You can use the command lpfilter -f all -l to list all print filters currently registered in the system. You will probably want to pipe the output to more since even the vanilla Solaris install has many pre-installed filters.

Finally, you need to make the physical printer input types line up correctly with the filter. You should first create a printer using either admintool(1m) or lpadmin(1m). Regardless of which way you choose to setup the printer, you need to run lpadmin with the -I flag to indicate the input types. To make a newly created printer named ``nuts'' use the print filter that we added above, we execute the following command (this assumes you already created the printer):

# lpadmin -p nuts -I PCL5
It may be sufficient to do it in one step:
# lpadmin -p nuts -i /dev/bpp0 -I PCL5
This creates a printer called "nuts" which is connected to the device at /dev/bpp0 and accepts only PCL5 input. The type that you put after the -I should match the string you indicate on the ``Output Types'' line of the print filter file. In this case, we used ``PCL5'' in both places. This is a custom string, so you can use whatever name you wish as long as it does not conflict with one already being used in the system.


Testing it

Print something! One easy way is to start a web browser and print something. Make sure that the print job goes to the correct printer (although this printer is probably the default). Solaris should print a header page and then the contents of your document. On my system it also spits out a blank page at the end of each job (so recycle it somehow!)

Troubleshooting

Read the document carefully!
How do I get rid of the banner page?
Edit the file in /etc/lp/interfaces which corresponds to the printer you want to fix this on. Around line 332 there is a line that says nobanner="no". Change it to nobanner="yes". That's all, it will never spit out a banner page.
How do I get rid of the blank trailing page after each print job?
Edit the same file as in the previous question (/etc/lp/interfaces/nuts for example). Around line 992 change the echo statement in the then statement:
         if [ -n "${FF}" -a "no" = "${nofilebreak}" ]
         then
            echo "${CR}\c"
#           echo "${CR}${FF}\c"
         fi
		

Nifty variations

Here are some print filters that I made for convenience:
ps2up2pcl.fd
Changes the postscript input to print two pages on each sheet of paper and then sends that to ghostscript. You need the psutils package.
ps4up2pcl.fd
Changes the postscript input to print four pages on each sheet of paper and then sends that to ghostscript. You need the psutils package.

Comments/Questions: ussn@toocool.calpoly.edu
IMPORTANT NOTE: The people who receive mail on the ``ussn'' alias are students at the university, and are not paid to provide support. If you are a student of Cal Poly we will do everything we can to help you resolve your problem. If you are not affiliated with Cal Poly we probably won't have time to help unless your problem is fairly common or straight forward.

Written By: Brian Kurotsuchi
$Id: solaris-printing.html,v 1.3 1999/04/27 00:27:26 bkurotsu Exp $
( xxx ) as of 06/01/98