(Answer) (Category) Linux on PowerPC FAQ-O-Matic : (Category) System Configuration : (Category) Printing :
Can I print to a PC-compatible DeskJet?
Sure you can!  In fact, you can turn a lowly HP DeskJet 500 into
a fast,cheap PostScript inkjet printer, by doing the following:

Hardware:
---------
If you can, get hold of one of those DB-9 to parallel-port cables
that are packaged with GDT's PowerPrint software. (Ask in the 
newsgroups, and don't pay anything more than beer money, OK?) If
you can't get one of these, an Imagewriter I  cable for the DeskJet's
serial interface will do (even though your print speed won't be 
anywhere near as fast).  If you use the serial option, be sure to
consult the DeskJet manuals for DIP switch settings.

Linux Setup:
------------
Create an entry in your /etc/printcap file that looks like this:
 
hpps|HP DeskJet 500 (and up) for PostScript, using gs for rasterization:\
        :lp=/dev/hpdj:sd=/var/spool/hpps:\
        :mx#0:\
        :sh:\
        :sf:\
        :if=/usr/local/bin/hpps:\
        :lf=/var/log/lpd-errs:

Be sure to create a /var/spool/hpps directory, and to create a soft
link from your printer port (/dev/cua1) to /dev/hpdj for your device.
(See similar answers in this category for the lurid details of setting
up a printer queue.)

As for the executable /usr/local/bin/hpps (which you are defining as
an input filter in the above printcap stanza), just use this perl script:

------ top of file
#!/usr/bin/perl

#
# You will need to change values for your variables, as 
# appropriate for your printer.
#
my( $cmd ) =  "| /usr/local/bin/enscript -M Letterdj" .
              "  --pass-through --lineprinter -o - |"  .
              " /usr/local/bin/gs -q -dNOPAUSE -sDEVICE=deskjet" .
              " -sOutputFile=- - ";

my ($linespeed, $stty_opts, $device) = 
# if you are using a GDT PowerPrint cable, use the line below
   (57600, "raw -echo -crtscts ixoff ixon", "/dev/hpdj");
# if you are using a serial cable, comment out the line above
# and use this line instead:
#  (19200, "raw -echo crtscts -ixoff -ixon", "/dev/hpdj");

#   Configure printer's serial port
system ("/bin/stty $linespeed $stty_opts < $device ");

#  Pipe input to this script to a command for generating
#   appropriate output for our printer ("man perlipc" for details)...
open (SCRIPTED,$cmd) || die "Can't script?!";

#  Catch any signals wrt breaking pipes (naughty naughty)
local $SIG{PIPE} = sub { die "Scripter pipe broke" };

#  Let 'er rip...
while (<STDIN>){
   print SCRIPTED $_;
}
close SCRIPTED || die "Can't close temporary pipe.";
exit 0;

--- end of file

..and set this script's permissions with the command:
chmod 755 /usr/local/bin/hpps.

For the record, this script invokes the system's stty command
to set printer port attributes, and does so on every print job.
Why do I do this?  Let's say my DeskJet is on the fritz, and I
borrow a StyleWriter II.  You can probably guess that the port
attributes will be wildly different for the StyleWriter.  
No problem: We simply create another printer queue (and doctor 
a copy of the script above accordingly -- stty flags, enscript 
flags and args etc. must be tweaked.. okay, so maybe there is a 
problem =-) ).  Once the queue is set up & started, I can simply plug 
in the new printer, and redirect jobs to the new queue.  In short, 
configuring the new printer & queue may be painful; switching 
between the two types from then on, however, is not.

Use lpc to start up your new queue, and you're ready to go.

-- Dan Caugherty (caffeine1@mindspring.com)
caffeine1@mindspring.com
Hold on!  There's a change required for LinuxPPC 1999!

The newest version of lpd has a capability it should have had for
some time: passing cmd line arguments to filters.  While the script
above works for older versions of lpd, it WILL FAIL with the latest
one! (/var/log/lpd-errs ..or wherever your error output may be..
will contain lines like "-h66 : could not open file".)

So, use THIS script instead of the one above. Note also that the
Perl "pipe" used for formatting output has been tweaked:

--------script begins
#!/usr/bin/perl

#
# You will need to change values for your variables, as
# appropriate for your printer.
#

$#ARGV = -1;  #Ignore cmd line arguments (who cares??)

my ($enscript_it) =
   "| /usr/bin/enscript -M Letterdj --pass-through --lineprinter -o -";

my ($rasterize_it) =
" | /usr/bin/gs -q -dNOPAUSE -sDEVICE=deskjet -sOutputFile=- -";

my ($linespeed, $stty_opts, $device) =
# if you are using a GDT PowerPrint cable, use the line below
(57600, "raw -echo -crtscts ixoff ixon", "/dev/hpdj");
# if you are using a serial cable, comment out the line above
# and use this line instead:
#  (19200, "raw -echo crtscts -ixoff -ixon", "/dev/hpdj");

#   Configure printer's serial port
system ("/bin/stty $linespeed $stty_opts < $device ");

#  Pipe input to this script to a command for generating
#   appropriate output for our printer ("man perlipc" for details)...
$cmd = $enscript_it . $rasterize_it;
open (ENSCRIPT, $cmd) || die "Can't enscript?!: $! ";

#  Catch any signals wrt breaking pipes (naughty naughty)
local $SIG{PIPE} = sub { die "Scripter pipe broke somewhere" };

#  Let 'er rip...

while(<>){
   print ENSCRIPT  $_;
}                
close ENSCRIPT || die "Can't close temporary pipe.";
exit 0;

-----script ends


Hope this helps,
-- Dan Caugherty (caffeine1@mindspring.com)
caffeine1@mindspring.com
[Append to This Answer]
Previous: (Answer) Why does lpr crash and/or consume all available memory?
Next: (Answer) How do I print to my Stylewriter 4100 ?
This document is: http://www.jonh.net/cgi-bin/lppcfom/fom?file=470
[Search] [Appearance]
This is a Faq-O-Matic 2.717d.
Hosted by anduin.org and SourceForge Logo