*BSD News Article 94542


Return to BSD News archive

Path: euryale.cc.adfa.oz.au!newshost.carno.net.au!harbinger.cc.monash.edu.au!munnari.OZ.AU!news.ecn.uoknor.edu!feed1.news.erols.com!cpk-news-hub1.bbnplanet.com!news.bbnplanet.com!newsxfer3.itd.umich.edu!agate!news.Stanford.EDU!nntp.Stanford.EDU!andrsn.stanford.edu!andrsn
From: Annelise Anderson <andrsn@andrsn.stanford.edu>
Newsgroups: comp.unix.bsd.freebsd.misc
Subject: Re: HP Printer setup.
Date: 27 Apr 1997 04:40:59 GMT
Organization: Stanford University
Lines: 99
Message-ID: <5julcr$9kj$1@nntp.Stanford.EDU>
References: <336118DC.167EB0E7@caatpension.on.ca>
NNTP-Posting-Host: andrsn.stanford.edu
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 8bit
cc: amathenge@caatpension.on.ca
X-Newsreader: TIN [UNIX 1.3 unoff BETA release 961126]
Xref: euryale.cc.adfa.oz.au comp.unix.bsd.freebsd.misc:39810


In comp.unix.bsd.freebsd.misc Andrew Mathenge <amathenge@caatpension.on.ca> wrote:
> I have a problem setting up a filter for a HP4si (and HP3si) printer
> for printing simple ascii files.

> I know that I can use a2ps to convert the ascii file to postscript and
> then send it... but I would like to be able to use simple text editors
> to send it and have the filter applied automatically.

> Advise please... with some examples.

> Thanks in advance.

> Andrew.

apsfilter is pretty good....but you can also put an entry for a
"printer" in /etc/printcap; I have one that looks like this (the
printer is called pcl or lp4, and there's no separate spooler set
up for it):

pcl|lp4:\
	:lp=/dev/lpt0:\
	:sd=/var/spool/ljet2p-raw:\
	:lf=/var/spool/ljet2p-raw/log:\
	:af=/var/spool/ljet2p-raw/acct:\
	:if=/usr/home/andrsn/bin/setup:\
	:mx#0:\

The "if" line above calls a script file "setup" that looks like this:

#!/bin/sh

printf "E&k3G" && cat && printf "\f" && exit 0
exit 2

so when I want to print I just type lpr -Ppcl filename
In the above, the ^[ before the E (if it made it through Usenet)
is a decimal 027 entered in vi (in insert mode) with ctrl-V<esc>

The directory in which this file resides needs to have 755 permissions.

Here's another option--a shell script called qp (for quick print) that
prints a file with the command qp filename

#!/bin/sh

awk -f ~/bin/qp.awk $1 | lpr

This above shell script calls qp.awk and sends the file to the
printer; here's qp.awk:

BEGIN {
	printf("E&k3G(s0p12v0s0b3T&a06L")
	}
$0 ~ (/\n/)
	{print}
END {
	printf("E")
}

This little awk script initializes a printer that speaks PCL (rather
than postscript), tells the printer to deal with unix line endings,
sends a font string to the printer, and also sends a left margin to
the printer.  All lines of the file (including blanks) are printed.
In the end block the script sends the printer initialization code
again.  (There are four 027's in the above.)

Here's another awk script, called in a similar manner, that changes
tabs to spaces, good for printing code that would otherwise fall off
the page, because the Laserjets I use think a tab deserves 8 spaces:


BEGIN {
	printf("E&k3G(s0p12v0s0b3T&a04L")
	TABLEN = "  "
	}
$0 ~ (/\n/)
	{
	if ( match($0,/^[ \t]+/ ))
		{
		gsub(/\t/,TABLEN,$0 ) 
		print $0}
	else print $0}
END {
}

Finally, I got sufficiently frustrated even having apsfilter, because
I still would have had to learn *roff, TeX/LaTeX, or how to code
postscript to actually produce documents that had different type
faces, bold, underlining, italics, and so forth in them that I wrote
a couple of awk scripts to deal with files created with a text editor
that having PCL printer codes in them.  Alternatively you can use
the staroffice port (really terrific, but takes a lot of space) or--
what seems to be a rather common quick solution--mark up the text
with HTML and print it with Netscape (to do that you may need to have
apsfilter installed.

So there are some examples.

Annelise