Using GhostScript under LP

Norman A. Jacobs
Sun Microsystems, Inc.

Disclaimer: I have created the contents of this page strictly on my own. You use any of this without any official support and at your own risk.

What is GhostScript?

GhostScript is a PostScripttm interpreter available under the GNU Public License free of charge. It can be used to provide a PostScripttm RIP for a wide variety of non-PostScripttm dot matix, thermal, inkjet, and laser printers. It also can be used to preview PostScripttm documents on a number of platforms and the Aladdin version can convert PDF documents to PostScripttm

How do I get it ?

GhostScript is distributed in source from a number of FTP servers on the internet. Below is a list of only some of the many site from which you can download a copy:

How do I use GhostScript?

If you have downloaded a Solaristm Package containing binaries for you system, you will simply need to add the package to your system, write and interface script (or filter definition) to plug it into LP, and configure it under LP. If you have downloaded the source, you will need to configure the source base to build under Solaristm, Build the Software and install it.

Installing a Solaristm Package...

	% /bin/su
	# pkgadd -d (solaris package location) all

Configure, Building, and Installing from source...

	% cp unix.mk Makefile
	% edit Makefile make the modifications that follow:
		* installation location
		    The installation location is controlled by setting
		    the "prefix" variable in the Makefile to the
		    location you wish to install in.  I would recommend
		    using a location like /opt/GhostScript or /usr/local.
		* supported devices
		    The devices you wish to support is controked by the
		    "DEVICE_DEVXX" variables.  A number of devices are
		    supported by default.  You will want to look and see
		    that that all of the devices you are interested in
		    are configured in these variables.   
		    The default behaviour is not to build support for
		    SPARCPrinters on a Sparc system.  It you would like
		    to support a SPARCPrinter from a Sparc system, you
		    will have to add "sparc.dev" to one of the DEVICE_DEVXX
		    variables and make sure you "lpvio.h" header file is
		    somewhere in the include path for the build.
	% make all
	% make install

Writing a suitable interface script...

We have a whole web page dedicated to writing suitable interface scripts under LP. Contained in that web page are a number of example interface scripts that could be used to drive printers using GhostScript under LP.

Configuring LP...

I suggest that when you configure LP to drive a SPARCprinter under LP on a Sparc system, that you use an interface script to do so. The reasoning is simply that GhostScript drives SPARCprinters slightly differently than any of the other printers that it can drive. With the SPARCprinter, GhostScript RIPs the PostScripttm and passes the images down to the device using the combination of ioctl(2)s and write(2) one would normally use to pass data to the device and get it to print the page. With all other printers, GhostScript generates a datastream that makes no assumptions on how the printer is connected.

note: Because LP runs the interface script as lp or the submitting user, and the fact that GhostScript must open the lpvi or spd device when driving a SPARCprinter, the lpvi device must be set to mode 0666 or GhostScript must be SGID to a group that has privilege to to read/write the device. Failure to do this will result in no output and the following message from GhostScript:

	Error: /invalidfileaccess in --.outputpage--

SPARCprinter

	% /bin/su
	# lpadmin -p printer -v /dev/null -I postscript -T ps \
		-i /opt/PRINTtoys/lib/interfaces/SPARCprinter
	# cd /etc/lp/fd ; for filter in *.fd ; do
	> name=`basename $filter .fd`
	> lpfilter -f $name -F $filter
	> done
	# accept printer
	# enable printer
If your printer is not a SPARCprinter, You can configure LP in one of two manners. The first method is just like configuring a SPARCprinter as is done above, but instead of using "/dev/null" as the device, you would use the actual device that the printer is connected to.

Other Printer

	% /bin/su
	# lpadmin -p printer -v /dev/bpp0 -I postscript -T ps \
		-i /opt/PRINTtoys/lib/interfaces/GSinterface
	# cd /etc/lp/fd ; for filter in *.fd ; do
	> name=`basename $filter .fd`
	> lpfilter -f $name -F $filter
	> done
	# accept printer
	# enable printer
The alternative method of configuring LP to use GhostScript is to configure GhostScript as a a slow filter that converts from PostScripttm to an input type accepted by the printer. One of the advantages of this method is that communication with the printer uses one of the standard interface script, so there is generally slightly better status reporting, and network attached printers can be included using either the vendor supplied support, or the Solaristm support in 2.6

Using a slow filter

	% /bin/su
	# lpadmin -p printer -v /dev/bpp0 -I simple,hpgl -T hplaser \
		-i /usr/lib/lp/model/standard
	# cd /etc/lp/fd ; for filter in *.fd ; do
	> name=`basename $filter .fd`
	> lpfilter -f $name -F $filter
	> done
	# lpfilter -f GhostScript -F /opt/PRINTtoys/lib/GS_HPGL.fd
	# accept printer
	# enable printer

The SPARCprinter

If you are configuring GhostScript to function as a RIP for a SPARCprinter, you do need the lpvi device driver and header file as stated above. It is recommended that you get your copy of the driver and header file off of the software support CD that was bundled in with your printer. If you can't seem to locate the CD, I have packaged the driver and header in as Solaristm package that you can add to your system.
	% /bin/su
	# pkgadd -d SUNWlpvi.pkg SUNWlpvi
note: this package is unofficial and unsupported, as such, it will not be patched or updated. For an official lpvi driver you must use the NeWSprint Distribution media.