Hack 95. Print to Unsupported Printers


you can't print from Linux.Linux's support for printers increases
with every passing day; the
team at http://linuxprinting.org
and the army of software developers building free drivers for new
printers do a sterling job. However, printers are still on the market
(and new ones are being released each day) that Linux does not
support; no driver is available, so Linux users cannot print to these
unfortunate devices. This problem has no direct solution, but if you
find yourself in this situation and you can attach your printer to a
Windows machine, you can hack a solution.Under normal circumstances a printer connected to a Windows machine
can be used by Linux (via Samba). But this doesn't
work when a Linux printer driver is not available. This hack delivers
an interesting solution to this problem. It uses a generic printer
driver on Linux to send a PostScript print job to a Windows machine
sharing the printer. The Windows machine interprets the PostScript
using a local copy of Ghostscript, which then sends the information
to the Windows printer driver and on to the printer.
11.5.1. How Printing Works
The normal process of printing from Linux to a
supported
shared Windows printer is as follows:
- You print from the application (say, a word processor) on the Linux
box.The print job goes to the print server on the Linux box, which is
likely to be CUPS. CUPS has a printer driver for this model of
printer, and it converts the print job into a set of instructions
telling the printer how to print the job. (These instructions are, to
some extent, printer-specific, which is why a specific driver is
required for each printer.)The stream of instructions flows across the network to the print
server on the Windows machine.The instructions are fed by the Windows print server to the printer.The printer prints the job.
steps. After it has been set up, the process works like this:
- You print from the application (say, a word processor) on the Linux
box.The print job goes to the print server on the Linux box. CUPS
processes the print job using a generic printer driver that can
output PostScript. PostScript is a generic way of describing print
jobs; if the "set of instructions"
that describe how to print a job are in PostScript, any printer that
understands PostScript can understand them.The stream of PostScript instructions flows across the network to the
print server on the Windows machine. At this point, they are unusable
by the Windows printer driver.The instructions are fed by the Windows print server to a
"redirected printer," which is
actually a connection to Ghostscript, a free software PostScript
interpreter.Ghostscript, which is running as an application on the Windows
machine, sends the job to the real printer (it
can print to the real printer because it is running on Windows and
can therefore use the Windows printer driver).The printer prints the job.
hack covers setting up Ghostscript as a pseudoprinter.
11.5.2. Creating a Redirected Printer
The first step in getting the redirected
printer working is to install
GhostScript and some supported programs on Windows. Download and
install the following programs:Ghostscript (http://www.cs.wisc.edu/~ghost/doc/AFPL/get814)RedMon (http://www.cs.wisc.edu/~ghost/redmon/)GSview (http://www.cs.wisc.edu/~ghost/gsview/index)
GSview is sometimes packaged with Ghostscript, so you might not need
to install it separately.Within the directory containing gsprint.exe
(C:\GS\GSVIEW, by default), create the file
gsprint.cfg with the following content:
-noqueryYou can remove the -color line if you are using a
-color
-printer
windows_printer_name
-ghostscript
"C:\GS\GS8.14\BIN\GSWIN32C.EXE"
black-and-white printer. The path in the last line should be the
actual path to gswin32c.exe. The line
windows_printer_name must
exactly match the name the real Windows printer
has in the control panel. Be careful about spaces; there must not be
any trailing or leading spaces on any of the lines, and there must
not be any blank lines in the file (including at the end).Next, create a new printer in the control panel that uses the Apple
LaserWriter II driver (this driver is for a PostScript printer). This
PostScript printer is necessary, because your Linux box knows how to
print to PostScript printers, but not to your Windows printer; next,
you'll set up the PostScript printer so that it
passes documents sent from your Linux box on to Ghostscript. View the
properties of the just-created PostScript printer, click Add Port on
the Ports tab, and select "Redirected
port" (this option appears only once you install the
RedMon utility). Call the port
RDR1: and click OK. Click
Configure Port and enter the following settings:
Field | Value |
---|---|
Redirect to program | C:\GS\GSVIEW\GSPRINT.EXE |
Arguments for program | - (a single dash, no spaces) |
Output | Program handles output |
Run as user | Select this option |
printer's properties and set the Port to be
RDR1:. Now print a test page to the PostScript
printer; it should print out of the real printer. The print job that
is sent to the PostScript printer is being sent on to Ghostscript
(the printer is "redirected to a
program," as noted in the previous table), and then
Ghostscript prints the job to your Windows printer, because it was
configured to do so (when you put the name of the Windows printer in
gsprint.cfg).The printer should be available to all users; to do this, you need to
copy the settings in the registry that define the printer from your
user account to the default user account. Export the registry key
HKEY_CURRENT_USER\Software\Microsoft\Windows
NT\CurrentVersion\Devices from RegEdit to a file. Edit the
exported file, and change the line
[HKEY_CURRENT_USER\Software\Microsoft\Windows
NT\CurrentVersion\Devices] to
[HKEY_USERS\.DEFAULT\Software\Microsoft\Windows
NT\CurrentVersion\Devices]. Save the changed file, and
double-click it to load it into the registry.Finally, go back to the PostScript printer's
properties, choose Ports, select RDR1: and Configure Port, and
uncheck Run as User. Now share the PostScript printer with a short
share name (less than eight characters). Remember this name:
you'll need it shortly.
11.5.3. Printing to the New Printer
On the Linux machine, set up the printer as you would normally set up
a Windows printer. For example, under GNOME, in the Printers window,
click Add Printer
(SMB), and enter the NetBIOS name of the Windows box under Host. Put
the share name you created earlier in the Printer field. You might
also need to add a username and password to access the printer;
consult the Samba documentation for details. Select the printer type
as an Apple LaserWriter II or a generic PostScript printer.Under KDE, select "SMB shared printer
(Windows)" from the KDEPrint Add Printer wizard, and
enter the details as for GNOME. Again, select the printer type as an
Apple LaserWriter II or a generic PostScript printer. Now your Linux
applications should be able to print to the printer successfully!For more information and details, take a look at http://mywebpages.comcast.net/heretrythis/hp3100/psemuntl.Stuart Langridge