1 TITLE: Printing From Scratch
3 LFS VERSION: anything with a kernel >=2.2
5 AUTHOR: Uli Fahrenberg <uli at math dot auc dot dk>
8 A very simplistic, yet usable printing setup. Spooler-less. Doesn't
9 get more simple than this. Formerly known as the Printing Minority
14 Setting up a Linux box for printing can be very easy. If you your setup is
15 simple: One computer and one printer which you want to communicate, and that's
16 about it, this hint is for you. If you want to share your printer between
17 several computers or anything fancy like this, I cannot help you.
23 AFPL, GNU, ESP, whatever; see BLFS book for details.
27 Again: See BLFS book for how to install these.
31 This is version 2 of the Printing Minority Report, a printing hint originally
32 written by Declan Moriarty. When I used it (the original hint) to get my
33 printer working, I cooked up a script to replace the usual-on-unix lpr
34 command. I submitted the script to Declan, and the next thing I knew was that
35 Declan handed over the hint to me.
37 Thanks to Declan for the original hint, and to Bill Maltby for clearing up
38 some issues on how to echo stuff to printers the GoodWay[TM].
43 Check that you have printer support in your kernel, either compiled-in or as a
44 module. My config is as follows; you might not need the last two PARPORT_*
49 CONFIG_PARPORT_PC_CML1=y
50 CONFIG_PARPORT_SERIAL=y
56 Check if your printer is working and connected:
58 echo -en "blah\f\r" > /dev/lp0
60 (substitute lp0 with the port your printer is connected to)
62 If your printer spits out a piece of paper with the word `blah' on it,
63 good. If it doesn't, worry.
65 If your printer is an Epson, the above command most probably will not work. In
66 this case, the following info contributed by Jeroen Coumans might help:
68 Epson printers don't work without first being given a special
69 character. The gimp-print util escputil is commonly used for that
70 (it's probably possible to do this without first installing
71 gimp-print, but I don't know how). This is the command which works for
74 escputil -r /dev/usb/lp0 -i
76 You might want to install gimp-print anyway (i won't tell you how, though (but
77 it appears to be a piece of cake)), as Epson printers are poorly supported by
78 Ghostscript. Otherwise, to build just escputil,
80 ./configure && make -C lib && make -C src/escputil
87 Install your favourite version of Ghostscript.
92 Type gs -h at a prompt and select your printer from the pageful of drivers
93 that it gives up. If your driver is not shown, go back to step 3 and install
94 another version of Ghostscript. AFPL and ESP Ghostscript differ in what
95 printers are supported. (Hint: some kind of package management comes in handy
98 If you don't know what driver to select to get your printer working, go to
100 http://www.linuxprinting.org/
102 and search their database for your printer. You might be told that you need
103 some additional software; HPIJS, pnm2ppa, or others. If you do need some extra
104 software, you're on your own. Here we only deal with Ghostscript-supported
105 printers. (But read on, the hint might still be of use for you.)
110 Test your setup. Get yourself a ps file (pdf will do, too), and run
112 gs -q -dBATCH -dNOPAUSE -dSAFER -sDEVICE=<your-printer-driver> \
113 -sOutputFile=/tmp/testit <your-file>
115 You'll find some ps files in the Ghostscript examples directory; with me this
116 is /usr/share/ghostscript/8.00/examples/. This command should give you a
117 (probably rather large) binary file /tmp/testit; if you're lucky (I was),
122 will identify it as printer data. It may also tell you that the paper size does
123 not fit what you have in your printer; if this is the case, adding
124 -sPAPERSIZE=<your-papersize> to the gs command above will help. The other
127 -q tells gs not to display anything & saves it looking for X.
128 -dBATCH tells gs to quit after processing - always a good idea.
129 -dNOPAUSE gs will not wait for a key-press after each page.
130 -dSAFER stops gs from deleting or zapping anything.
131 -sDEVICE= your printer driver. Be exact and case sensitive. gs is
132 stupid. Use the spelling on the info at 'gs -h'.
133 -sOutputFile= write to this output file (congratulations for guessing!)
135 If everything looks OK, you can
137 cat /tmp/testit > /dev/lp0
139 (again, replace lp0 with the port your printer is connected to). This should
140 get <your-file> out to <your-printer>.
142 Both the commands above might give you some trouble with permissions if you do
143 them as an ordinary user. If the gs one does, execute
147 and kick yourself for running a machine unusable for ordinary users. If the
148 cat command bails out with some 'Cannot write to /dev/lp0' blah, you can
149 either decide that only root should be allowed to access your printer, or you
150 can be a little lax on some (minor) security issues and do a
154 If you want to use the lpr script below for printing, you should do the
160 If you got here, you have your printer working. You can leave it at this; what
161 you did in step 5 was printing after all. If you want to be slightly more
162 fancy, the script below will provide you with an lpr command, to be used
167 or by having lpr as (the last) part of a pipe. This should let you use most of
168 your favorite application's `Print' buttons/commands directly.
170 Another advantage of the script below is that it does not make use of
171 temporary files, thus avoiding a) cluttering /tmp with all kinda crap, and b)
172 some security hazards. On the other hand, if you want ordinary users to print,
173 you have to give them access to /dev/lp0 (or whatever port your printer is
174 connected to), see above.
176 Here we have the script; as you can see, there's some adjusting to do for
177 you. I have yet to encounter applications that won't print with this script;
178 if you do, please notify me.
180 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
181 cat > /usr/bin/lpr << "EOF"
184 #################### Adjust to your needs/desires.
188 LOCKFILE=/tmp/.${LP}-lock
189 #################### End Adjust
191 # Prints file to printer $DEVICE connected at /dev/$LP,
192 # using paper size $PAPER.
193 # Usage: lpr <ps or pdf file> ( or cat <ps or pdf file> | lpr )
195 # Uli Fahrenberg, early 2003. This file is in the public domain.
197 if [ -e $LOCKFILE ] ; then
198 echo "Error: printer is locked ($LOCKFILE exists)"
203 if ! [ X$FILE = X ] ; then ### We have a filename as an argument.
204 if ! [ -r $FILE ] ; then
205 echo "Error: Cannot read file $FILE"
209 FTYPE=$(file -bL $FILE | awk '{print $1}')
210 if ! [ $FTYPE = 'PDF' ] && ! [ $FTYPE = 'PostScript' ] ; then
211 echo "Error: $FILE is not a PS or PDF file."
215 ### Comment this out if you want lpr to be quiet:
216 echo -n "Printing $FILE... "
219 trap 'rm -f $LOCKFILE' EXIT ; \
220 gs -q -dBATCH -dNOPAUSE -dSAFER -sDEVICE=$DEVICE \
221 -sPAPERSIZE=$PAPER -sOutputFile=- $FILE \
224 ### Without the sleep, some apps delete $FILE
225 ### faster than gs can read it:
227 ### Comment this out if you want lpr to be quiet:
230 else ### We have no filename argument, so we try stdin
231 DATA="$(</dev/stdin)"
233 trap 'rm -f $LOCKFILE' EXIT ; \
235 | gs -q -dBATCH -dNOPAUSE -dSAFER -sDEVICE=$DEVICE \
236 -sPAPERSIZE=$PAPER -sOutputFile=- - \
240 chmod 755 /usr/bin/lpr
241 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
244 STEP 7 (even more optional):
246 So now you can print postscript and pdf files on your printer. If you want to
247 print other kinds of files (plain text files, say, e.g. LFS hints...), you
248 might find the a2ps (AnyToPS) package handy. Also, for manipulating postscript
249 files, the psutils package is a good thing to have installed. Both packages
250 are covered in the BLFS book.