[ale] Printer question
John Mills
john at mills-atl.com
Thu Apr 26 13:47:27 EDT 2001
H'lo -
Elaborating on this:
On Thu, 26 Apr 2001, Jeff Hubbs wrote:
> Given that many Linux print systems involve Postscript at some stage in the
> process, do you think it would be possible to pipe the PS through some Perl
> that inserts a header section (if that is in fact how Postscipt handles
> headers)?
It depends on what you are printing. If the raw contents can be
formatted on the page (such as many text files), you or 'lp' can
pass the job through a filter and add what you want. For example, the 'P'
pager in 'lp' puts a simple datestamp and page number at the top of each
page. If you pass the file through 'nenscript' before the printer, it will
get a simple (-g) or graphical (-G) header on each page. See the
respective man pages.
With the gracious help of members of this list, I built up the attached
bash script which is driven by a file list and uses 'groff' to produce
PostScript, which 'gs' then translates for the printer. ["head bone
connected to the ..."] It trips on a few constructs, such as lines
starting with '.', but that could be fixed. You can make headers and
footers to your taste, but one of the footers comes out a datestamp in the
version attached.
The stream edit lines are to catch content which would confuse 'groff',
and are a bit more adapted to Ada than C; these can certainly be improved.
It was pretty unhappy digesting LaTex. &8-P
Providing the initial page number as an arg allows you to print large
dumps in smaller batches, or recover if the printer eats your job. (It was
originally written to handle an Ada listing of 2000+ pages, which I broke
up into smaller file sets to preserve the printer and my sanity.)
This is a 'work in progress' - feel free to improve it, or subdivide it to
serve your needs. It can run in a pipe, but presently the inward stream is
the _names_ of the files to print, as in:
"% ls zoo/ | list_runoff - "
prints the files of ./zoo/ in the order they come out of 'ls'. It's
pretty easy to modify the source of text. (You could do a forward or
reverse alpha-sort on the temporary filelist as an exercise.)
> > From: Matthew Brown [mailto:matthew.brown at cordata.net]
> > Is it possible to set up a printer on Linux such that when it prints a
> > document, it also prints a timestamp at the top of each page?
--
Regards -
John Mills
#!/bin/sh
#! conditionally set parameters
FIRSTPAGE=1
LISTNAMES=''
DOCNAME=''
PROJNAME=''
SECTNAME=''
PRINT_DATE=`date '+%d %b %Y'`
TEMPFILE='/tmp/printorder.'$$
if [ $# -ge 1 ]
then
LISTNAMES=$1
else
echo "usage: list_runoff <filelist> [initial page_no]" >&2
exit
fi
if [ $# -ge 2 ]
then
FIRSTPAGE=$2
fi
#! alphabetize list for correct output pagination
#! Disabled
#! sort -o $TEMPFILE -f $LISTNAMES
cat $LISTNAMES > $TEMPFILE
echo printing from \'$LISTNAMES\' with pages starting from $FIRSTPAGE, on $PRINT_DATE >&2
#! print each file's prefix and text to groff
for FILENAME in `cat $TEMPFILE`
do
if [ -f $FILENAME ]
then
cat - << MARKER
.nr PS 10
.R
.P1
.nr PO 1.25i
.nr LT 6.5i
.nr LL 6.5i
.nr HM 1.25i
.nr FM 0.5i
.pl 702p
.ds LH \fBFILE: $FILENAME\fP
.ds CH
.ds RH \fB$DOCNAME\fP
.ds LF \fB$PROJNAME\fP
.ds CF \fB$SECTNAME%\fP
.ds RF \fB$PRINT_DATE\fP
.ND
.LP
.bp
.nf
.CW
MARKER
sed 's/\\/&e/g' < $FILENAME
fi
done |groff -mgs -n$FIRSTPAGE -Tps |lpr
# to supress burst-sheet:
# done |groff -mgs -n$FIRSTPAGE -Tps |lpr -h
if [ -f $TEMPFILE ]
then
rm $TEMPFILE
fi
More information about the Ale
mailing list