Printing minority report

Declan. Moriarty declan.moriarty at
Wed May 14 07:53:44 PDT 2003

I am attaching an updated copy. Changes are mainly to remove typos, and
to add a script contributed by Ulrich who has automated it.

His tiny script informed by my farting about with aliases now replaces the 
function of lpr on a standalone system.

Why install a print program?

I'll mention it on the list when you have it up.


	With best Regards,

	Declan Moriarty.
-------------- next part --------------
TITLE:		The Printing Minority Report

LFS VERSION:	3.3 (Any, really)

AUTHOR:		"Declan Moriarty"<declan.moriarty at>

SYNOPSIS:	Quick Easy Printing without all those (expletives deleted) 
		print programs


For those without Postscript printers who get pissed off big time with
printing programs in linux and only need basic functionality, one
dissented loser with all this printing crap took the following way out. 
Printing is accomplished by ghostscript, and a simple but effective script
kindly contributed by Ulrich Fahrenberg <uli at>. All the other 
preprocessor programs, and post processors that make printing such a drag
in linux can be junked. They are ALL redundant bloat!

Get a Word Processor - Abiword is mine. A hint is there, and it
worked for me. If it doesn't work for you, argue with him, not me. 

If  you haven't done anything right yet, build abiword first. It has loads
of nice fonts which you can include in ghostscript by adding
'--with-fontpath=/usr/local/share/AbiSuite/fonts' to the gs
'./configure'.  Otherwise see 8 below.

Get ghostscript. I used espgs-7.05. Get a display of that tiger up on screen, 
as per Ghostscript hints, printing hints, etc, etc, using these commands

cd <ghostscript source dir>
gs examples/

I won't bore you further on this. There is a ghostscript hint.From my 
inspection the gimp printer drivers for ghostscript seem to offer more 
promise than the cups ones. So a good set of options for ghostscript might
include the following
./configure --with-drivers=all --with-cups --with-gimp --with-fontpath=<etc>

2.  Type gs -h at a prompt and select your printer from the pageful of
drivers that it gives up. I have a BJC-4000 (bjc600 driver), but like a
true cheapskate, I use b/w cartridges, so bjcmono suits me. The bjc600
driver performs poorly, giving colour to a b/w printer. You may then
want to fire up vim and edit the ppd slightly.

vim /usr/local/share/ghostscript-7.05/filter/bjcmono.ppd

or whatever your ghostscript /filter directory is. Don't muck it up,
just change defaults to another blindingly obvious option. If you
screw up completely, delete and you can do another 'make install'.
Test this driver by executing the following commands from a console.

gs -q -dBATCH -dNOPAUSE -dSAFER -sDEVICE=<your-printer-driver>  \
-sOutputFile=/tmp/testit  <> .

There are good postscript files in the <ghostscript source>/examples
directory.  Give it a few seconds. Make sure your printer is on.
Follow this with

cat /tmp/testit > /dev/lp0

or whatever point in the /dev directory your printer resides in. Paper
& ink should flow relatively productively.Repeat until it does. If you
get a ghostscript crash, look for a wordlike 'invalidfileaccess' (file error)
as a hint to what went wrong. If you can see the file but not send it to
print,have you permission? If so,  it's your '-sDEVICE=' option or a
syntax error.

If you fall over trying to write to /tmp as a user, execute (as root)

chmod 1777 /tmp 

and kick yourself for being too security conscious.

3 I have  following alias  in /etc/profile or some config file like
that which bash reads.

alias lps='gs -q -dBATCH -dNOPAUSE -dSAFER -sDEVICE=bjcmono -r360   \
- sOutputFile=/var/spool/canon'

It is for postscript and pdf files.  The usage is  'lps < or
filename.pdf> . It hangs you there for a few seconds, and when it
returns,  /var/spool/canon has the file in canon printer language.

Less /var/spool/canon

should show you a binary file full of gibberish. Perfect!
The details after    ' -sOutputFile=' can be any filename.
 -sOutputFile=/home/your_dir/rude_word would work just as well. Those
options mean:
-q - tells gs not to display anything & saves it looking for X.

-dBATCH - tells gs to quit after processing - always a good idea.

-dNOPAUSE - tells gs to skip it's usual dance (requiring a keypress).

-dSAFER -  tells gs from deleting or zapping anything.

-sDEVICE= your printer driver. Be exact and case sensitive. GS is
stupid.Use the spelling on the info at 'gs -h'.

-r360 - tells the resolution to use. You may not need this. You hacked
the ppd, remember? Yours may be different. It's the dpi.

-sOutputFile= write to this output file (congratulations for guessing!)
Brew your own cocktail of these options. Refine & remember it, or write
it down.

4. I found I needed a few lines on top of the page with cat as my
printing tool.  I got them the lazy way vim  /tmp/header. It says "new
file"; hit insert, return 3 times, escape,  and :wq. You should have a
/tmp/header file with three blank lines ;-)

5. Another alias  in etc/profile to get it out to the printer

alias print='cat /tmp/header /var/spool/canon >/dev/lp0'

This sends my file /var/spool/canon to the printer after /tmp/header.
Alter the space with more or less return characters in the  header
file. The filename (I show /var/spool/canon) has to be the same in both
aliases.  Log out and in again, to get the profile read. Type


at a prompt to check they are being read.

6. Usage is as follows: 

	1. To use the aliases, print to file from any application, e.g.
save a file as /tmp/ from your wp. Then

lps /tmp/ && print

will write a file of raw data ready for your printer, and send it out to 
the printer.

	2. To send a text only file, you can either convert it to ps (open 
it in a word processor and print to file) or 

cp <textfile> /var/spool/canon && print

or cat /tmp/header <textfile> >/dev/lp0

either of which will send  your filename to the printer after your blank 
header file. This can be reduced to a single command by someone with the 
least bit of scripting acumen, but I haven't got that. Fortunately,  Ulrich 
Fahrenberg <uli at> has, and I have appended the script that he 
provided for this as section 10. It works!

A hidden gotcha is that multipage ascii docs will mess up by
missing headers and often a few lines between pages. Load them in
abiword, or any wp that will print to a .ps file, and that will sort
them neatly into pages. Go around & set defaults to your paper size.
Ulrich's script (section 10) ideally needs a text section to send a 
header at the top of each page of ascii. If you can dream it up,  
script it and send it to me for inclusion. You, of course, will get 

7. Some tidying up :-D.  Use 'make uninstall' targets on your
"printing" programs if they exist. Then, if cups
has you seriously browned off (like it has me), for example

	rm -rf /etc/cups
	rm -rf /usr/share/cups
	rm -rf /var/spool/cups
	rm -rf /usr/src/cups*
	rm  -rf /usr/share/docs/cups

All those unnecessary files in the /usr/bin & /usr/local/bin
directories (broken loser program to do what I'm doing with two
aliases): gsbj; gsdj gsdj500; gslp; lp; lpr; lpd; lpadmin; lpstat, and
probably lp*. You get the  idea.  Have fun, and don't come crying to me
if you mess up by overdoing it. You can always reinstall, and
reconfigure. It's your system. You're the boss. I suggest you choose a
directory for print files - NOT
/home/you/followed/by/a/long/directory/name but /tmp. You can then add a

rm -f /tmp/*.ps

to some startup or shutdown file to clean up printed matter on a
reboot.. If you're fussy & security conscious,
make that something fussy & secure like

rm -i /tmp/*.ps and play God with these files.

Note that we got to here without cups, a2ps, gimp, and a huge amount of the
formatters and translators that seem to gather around inferior print 
strategies. Sad to say, few of these have 'make uninstall' targets, but such 
could be manufactured by attacking the Makefile :-D. It would be wise 
here to make sure you don't chop anything you actually want. Later LFS versions
have a package manager, so this shouldn't be an issue.

8. An added refinement is to review the gs -h info. At the end it
mentions a number of places where ghostscript checks for fonts.
Let one of them symlink to wherever abiword hid it's selection
(/usr/local/share/AbiSuite/fonts on my system), so ghostscript can
tap in, in the vain hope that you might get a WYSIWYG word processor.
It might even work.

9. If you are still having problems, be aware that there are a useful set of
help documents in the .abw format which come with the abiword source tree which
AFAIK are not installed anywhere. These are in the ~/abi/docs/ subdirectory.
They give details of how to load windoze fonts, as well as the the best and
most logical explanation of the tortured intricasies of the Unix font and
locale systems that I have come across in some time. The abiword source is 
worth downloading for these alone, even if you hate the thing. Unfortunately,
in real M$ style, they are in abiword's individual .abw format. 

10. The first versions of this hint contained an appeal to savants for a 
printing script to automate this.

This script below (name it lpr locally) takes a .ps or .pdf file and 
spits it at the printer, something printer programs seem to find difficulty
with ;-). Ulrich Fahrenberg <uli at> contributed this, and we bow 
and scrape in his general direction :-).

Before you say it doesn't work, revisit point 7 and make sure you cleared all 
the other lpr programs out of the path. Install it somewhewre in the path and 
chmod it to 755. 

Usage is simple: it IS lpr, and does everything a 500K binary would: Print from the 'print' function in anything, or call it from  a command line or script.

At a stroke we have obsoleted megabytes of bloated crap associated with 
printing. More Power to you, Ulrich!

# By Ulrich Fahrenberg <uli at>
# Check the arguments to gs suit your printer
### Adjust next two lines to your needs.

DEVICE=ljet4  	## Your printer driver from 'gs -h' here
LP=lp0		## Your printer port 

# Prints file to HP LaserJet 1100 connected at /dev/lp0
# Usage: `lpr <ps or pdf file>' or `cat | lpr'

if [ -e /tmp/.lp-lock ] ; then
        	echo "Error: printer is locked  (/tmp/.lp-lock exists)"
        	exit 1
if ! [ X$FILE = X ] ; then ### We have a filename as an argument.
        if ! [ -r $FILE ] ; then
                echo "Error: Cannot read file $FILE"
                exit 1

FTYPE=$(file -b $FILE | awk '{print $1}')
        if ! [ $FTYPE = 'PDF' ] && ! [ $FTYPE = 'PostScript' ] ; then
                echo "Error: $FILE should be a PS or PDF file."
                exit 1
	        echo -n "Printing $FILE... "
	        (touch /tmp/.lp-lock;\
        gs -q -dBATCH -dNOPAUSE -dSAFER -sDEVICE=$DEVICE \
	        -sPAPERSIZE=a4 -sOutputFile=- $FILE > /dev/$LP ; \
           	rm /tmp/.lp-lock) & echo "Done."

else ### We are part of a pipe.
	(touch /tmp/.lp-lock;\
	echo "$DATA" \
	-sPAPERSIZE=a4 -sOutputFile=- - \
        > /dev/$LP;\
        rm /tmp/.lp-lock)&

Some day, someone may write a reliable printing program in linux, if it is
shorter than this people should convert. Mind you, this is pretty good. And 
it will be very difficult to be shorter.

Declan Moriarty.

More information about the hints mailing list