wiki:GhostScriptRasterPrinting

Ghostscript Raster Printing (a.k.a. Using Ghostscript as a Printer Driver)

Ghostscript includes a large number of built-in printer drivers, many of which are not otherwise supported by OS/2 or CUPS.

Normally, the way CUPS supports such printers is by calling a program called foomatic-rip which validates the incoming postscript print job, adds some extra options to it, and then calls Ghostscript with the predetermined parameters. Unfortunately, this doesn't currently work under OS/2 because foomatic-rip seems to dislike the postscript data generated by the OS/2 printer drivers (ECUPS.DRV, PSCRIPT.DRV, etc).

However, there is a way to print seamlessly to Ghostscript-supported printers, if some special configuration is used. Doing it this way bypasses foomatic-rip (and, strictly speaking, CUPS itself) entirely.

Most of the discussion below focuses on the printers in the Epson driver collection for Ghostscript, but it should work equally well for any built-in Ghostscript printer driver.

Basic Procedure

The Epson Ghostscript drivers discussed by Dmitry (below) are now included in Paul Smedley's distribution of Ghostscript, as of version 9.00, and also as an update to version 8.71 (this is included in the WPI distribution).

This technique describes how to send the print job directly from the application --> Ghostscript --> printer without having to go through the intermediate stage of running GSView. Basically, this is made possible using the new UNI.PDR universal port driver:

  • Install UNI.PDR (to \OS2\DLL)
  • Create a new port of type UNI.
  • Edit the port properties. We need to send the print job through two programs: Ghostscript, followed by whatever command actually sends the job to the printer. Unfortunately, UNI.PDR doesn't currently support piping the job through multiple programs, so you have to use a REXX script or similar to link the programs together.

The details of this REXX script depend on what kind of printer connection you have. The program that actually sends the data to the printer is going to be different for LPD vs. SMB network printers, and different again for local USB connections.

Two REXX scripts are attached here (see the attachments section at the bottom of this page).

  • GS2PORT.CMD is for printing to a locally-attached printer on a USB or parallel port (or some other port type). This script requires the EPRINT.EXE utility (also attached).
  • GS2LPR.CMD is for printing to a TCP/IP network printer using the LPR/LPD protocol.

Quick Instructions

  1. Make sure you have Ghostscript v8.71 with the updated DLL installed and working.
  2. Download the UNI.PDR port driver and copy UNI.PDR to \OS2\DLL.
  3. Download EPRINT and place the executable somewhere in your path.
  4. Get GS2LPR.CMD (for TCP/IP printers) and/or GS2PORT.CMD (for USB and other local printers) from this page and place them somewhere convenient (these instructions will assume they are in your \OS2 directory).
  5. Create your printer object in the WPS.
  6. Open the printer object properties notebook, go to the Output port page, click on Install new port and select 'UNI'. (If you don't see 'UNI' listed, select 'New port drivers', enter the path to \OS2\DLL and click on Refresh.)
  7. Edit the properties of the new UNI* port as follows:
    • Path and file: cmd.exe
    • Parameters:
      • For TCP/IP (LPR) printers: /c x:\os2\gs2lpr.cmd <model> <IP address> <queue name> %file%
      • For local printers: /c x:\os2\gs2port.cmd <model> <port name> %file%

The parameters do not include '<' and '>'. For TCP/IP printers, if there is no queue name then use '*' as the queue. For local printers, if you don't know the port name then use EPRINT /L to get a list of ports.

This procedure is described in more detail below.

Note: You should use Ghostscript version 8.71. Later versions (9.x) do not work reliably.



Printing to a Network Printer

I've used the following script to print to a TCP/IP (LPD) printer on the network:

/* GS2LPR.CMD - print to a TCP/IP printer through Ghostscript, using LPR.
 *
 * The top-level GhostScript directory should be set in the environment
 * variable GHOSTSCRIPT (or just edit the path directly in the file, below).
 *
 * Syntax: GS2LPR <model> <LPD server> <LPD printer> %file%
 */

CALL RxFuncAdd 'SysLoadFuncs', 'REXXUTIL', 'SysLoadFuncs'
CALL SysLoadFuncs

PARSE ARG model server printer jobfile
IF jobfile == '' THEN RETURN 1

logdir = VALUE('LOGFILES',,'OS2ENVIRONMENT')
tmpdir = VALUE('TMP',,'OS2ENVIRONMENT')
gspath = VALUE('GHOSTSCRIPT',,'OS2ENVIRONMENT')

/* Change the fallback path to Ghostscript as appropriate for your own system. */
IF gspath == '' THEN gspath = 'f:\gs\gs8.71'

IF logdir == '' THEN logdir = tmpdir
logfile = logdir'\gs2lpr.log'
tmpfile = SysTempFileName( tmpdir'\GS_?????.TMP', '?')

gscmd  = gspath'\bin\gsos2.exe -sDEVICE='model '-dBATCH -dNOPAUSE -sOUTPUTFILE='tmpfile' -q' jobfile
lprcmd = 'lpr.exe -a 0 -b -s' server '-p' printer tmpfile

'@echo off'
IF STREAM( logfile, 'C', 'QUERY EXISTS') <> '' THEN CALL SysFileDelete logfile
CALL LINEOUT logfile, 'Running GhostScript with command line' gscmd
CALL LINEOUT logfile
ADDRESS CMD gscmd '2>&1 >>'logfile
CALL LINEOUT logfile, 'Return code:' rc
CALL LINEOUT logfile, ''

CALL LINEOUT logfile, 'Printing job with command line' lprcmd
CALL LINEOUT logfile
ADDRESS CMD lprcmd '2>&1 >>' logfile
CALL LINEOUT logfile, 'Return code:' rc
CALL LINEOUT logfile, ''

CALL SysFileDelete tmpfile

RETURN 0

Using the above, the following UNI.PDR settings will allow printing to a networked Epson LP-9400 printer with TCP/IP address 192.168.1.100:

Path and file cmd.exe
Parameters /c c:\os2\gs2lpr.cmd lp9400 192.168.1.100 * %file%

The '*' is used for the LPR queue name in the event that no explicit queue name is needed (this is generally the case when the printer itself is acting as the print server).

You could presumably print to a Samba printer by using smbspool instead of lpr.

(Don't try to print through CUPS -- i.e. with cupslpr -- using this technique, because the job will already be in printer-specific format at that point; CUPS expects to receive Postscript input, and will choke as a result. In any case, you're presumably using this technique because printing via CUPS doesn't work in the first place.)



Printing to a Local Parallel or Serial Attached Printer

According to the Ghostscript documentation, it should be possible to print to a parallel or serial port directly from the port driver, without need of a REXX script. This is because the Ghostscript -o parameter supports these port types. This has not been tested, but the following options (assuming a printer on LPT1 and Ghostscript installed in f:\gs\gs8.71) for the UNIx port may work in this case:

Path and file f:\gs\gs8.71\bin\gsos2.exe
Parameters -sDEVICE=lp9400 -o lpt1 -q %file%

(Note that '-o lpt1' is equivalent to '-dNOPAUSE -dBATCH -sOUTPUTFILE=lpt1', at least according to the documentation.)

Alternatively, it's presumably possible to achieve the same effect by using the OS/2 PRINT command (with /D:portname) in place of lpr.exe in a REXX script similar to the one above; this has not been tested either.



Printing to a Local USB Attached Printer

Unfortunately, the OS/2 PRINT command doesn't work with USB ports. There are a couple of ways around this, but the best solution available (at the moment) is to use the EPRINT utility, available at http://www.altsan.org/os2/printing/#eprint (it should also be attached to this page).

Using this method, the UNI port settings for the printer object look something like:

Path and file cmd.exe
Parameters /c c:\os2\gs2port.cmd lp9400 EPSON_LP_9400_1 %file%

Here, EPSON_LP_9400_1 is the name of the USB port that OS/2 creates when the printer is plugged in to the computer. (You can find out what the correct port name is by using the EPRINT /L command, which lists all ports in the system.)

The script in this case looks like:

/* GS2PORT.CMD - print to a locally-attached printer through Ghostscript, using 
 * EPRINT.
 *
 * The top-level GhostScript directory should be set in the environment
 * variable GHOSTSCRIPT (or just edit the path directly in the file, below).
 *
 * Syntax: GS2PORT <model> <port name> %file%
 */*/
PARSE ARG model port jobfile
IF jobfile == '' THEN RETURN 1

logdir = VALUE('LOGFILES',,'OS2ENVIRONMENT')
tmpdir = VALUE('TMP',,'OS2ENVIRONMENT')
gspath = VALUE('GHOSTSCRIPT',,'OS2ENVIRONMENT')
IF gspath == '' THEN gspath = 'f:\gs\gs8.71'

IF logdir == '' THEN logdir = tmpdir
logfile = logdir'\gs2port.log'
tmpfile = SysTempFileName( tmpdir'\GS_?????.TMP', '?')

gscmd  = gspath'\bin\gsos2.exe -sDEVICE='model '-dBATCH -dNOPAUSE -sOUTPUTFILE='tmpfile' -q' jobfile
lprcmd = 'eprint' tmpfile '/D:'port

'@echo off'
IF STREAM( logfile, 'C', 'QUERY EXISTS') <> '' THEN CALL SysFileDelete logfile
CALL LINEOUT logfile, 'Running GhostScript with command line' gscmd
CALL LINEOUT logfile
ADDRESS CMD gscmd '2>&1 >>'logfile
CALL LINEOUT logfile, 'Return code:' rc
CALL LINEOUT logfile, ''

CALL LINEOUT logfile, 'Printing job with command line' lprcmd
CALL LINEOUT logfile
ADDRESS CMD lprcmd '2>&1 >>' logfile
CALL LINEOUT logfile, 'Return code:' rc
CALL LINEOUT logfile, ''

CALL SysFileDelete tmpfile

RETURN 0




Original Note

The original posting from Dmitry Froloff follows. This is mainly for historical interest now.

List of newly supported Epson printers:

epl2050 epl2050p epl2120 epl2500 epl2750 epl5800 epl5900 epl6100 epl6200 lp1800 lp1900 lp2200 lp2400 lp2500 lp7500 lp7700 lp7900 lp8100 lp8300f lp8400f lp8600 lp8600f lp8700 lp8900 lp9000b lp9100 lp9200b lp9300 lp9400 lp9600 lp9600s alc1900 alc2000 alc4000 alc4100 alc8500 alc8600 alc9100 lp3000c lp8000c lp8200c lp8300c lp8500c lp8800c lp9000c lp9200c lp9500c lp9800c

Why I made this build.

Our company bought Epson AcuLaser? C1900 color printer. This model is capable to work PCL5 mode but in B/W mode only and doesn't understand poscript., while I wish to print in color too. So I look for solution and found out that Epson sources are GPL now and exist as GS patch.

So I downloaded the latest GS (8.53 at the moment) and the latest Epson GS patch ghostscript-7.07.tar.bz2. I applied the patch (patched sources GS doesn't changed too much from 7.07 to 8.53 version) and built the modules with gcc 3.3.5, what mean that you need lib06 dll (you may take it here ). I also made some minor changes in main GS code to finish new printer support with OS/2 printing subsystem.

If You wish to print from GSView You'll need to need to make some changes in gsview printer.ini file. I'm not familar with it's grammar, so for my printer I simply add line in [Devices] section:

alc1900=1200x1200,600x600,300x300

I also create a new printer object with IBM NULL printer driver. May be there is no need to do this as GS send data to printer queue in raw mode? Now I'm capable to print pdf and ps files from GSView. To finish printer support to other OS/2 application I installed fake printer object which generate ps file. Now I print to this fake printer and it generate ps file. After that I simply print this ps file from GSView. This may be automated as well, as I'm at the beginning of the whole way

Unfortunatelly, I didn't find the universal solution for all aplication. For example, I use ScenicSoft? postscript color printer driver (imported with PPD file) in 2400 resolution for printing from OpenOffice? and Xerox 4900 postscript printer driver for printing from Mozilla (works fine only in 300dpi mode :\ )

What's the next?

I can add the same way most of HP printers support. It operate slightly different - via separate application named ijs server. I already built the server itself, so everything depend on your backward requests :)

-- Best regards. Dmitry.

Last modified 12 years ago Last modified on Apr 10, 2012, 12:31:50 PM

Attachments (3)

  • gs2port.cmd (1.0 KB) - added by Alex Taylor 12 years ago. REXX wrapper for printing to a local port (USB/parallel/etc) with Ghostscript as an inline print processor
  • gs2lpr.cmd (1.1 KB) - added by Alex Taylor 12 years ago. REXX wrapper for printing to a TCP/IP (LPR) printer, using Ghostscript as an inline print processor
  • eprint_05.zip (28.6 KB) - added by Alex Taylor 12 years ago. EPRINT command-line utility, required by GS2PORT.CMD

Download all attachments as: .zip