Typo
[linux_from_scratch_hints.git] / OLD / printing_minority_report.txt
blob6ba88a8da372ee48dc851118fb508685713f4146
1 TITLE:          The Printing Minority Report
3 LFS VERSION:    3.3 (Any, really)
5 AUTHOR:         "Declan Moriarty"<declan.moriarty@ntlworld.ie>
7 SYNOPSIS:       Get Printing in 60 minutes.
9 HINT:
11 For those without Postscript printers who get pissed off big time with
12 printing programs in linux and only need basic functionality, one
13 dissented loser with all this printing crap took the following way out. 
14 Printing is accomplished by ghostscript, and a simple but effective 
15 script kindly contributed by Uli Fahrenberg <uli@math.auc.dk>. This hint
16 does not install 10 packages and then tell you 'it all worked for me'.
17 I install a max of 3 and tell you how to hack them to your taste.
20 CHANGES: 
22         22nd May 2003: Trimmed aliases, halved self congratulatory
23         propeganda and bloat, converted to a more noraml hint style
24         form it's highly eccentric predecessor.Added a2ps as a
25         concession to deal with multipage ascii files.
27         16TH May 2003: Added 'lpr' script by Uli Fahrenberg to replace
28         ALL print programs. Caught some of my own spelling & grammar 
29         mistakes. Reworked opening boasts accordingly.
31 SOFTWARE:
33 GHOSTSCRIPT: 
34 ftp://ftp.easysw.com/pub/ghostscript/espgs-7.05.6-source.tar.bz2
36 ABIWORD:(or any other word processor entirely at your own discretion)
37 http://www.abisource.org and download from nearest mirror.
38 There are also Maxwell, OpenOffice, and many others. Choose yours.
40 (Optionally) a2ps (For multipage ascii documents only)
41 http://www.infres.enst.fr/~demaille/a2ps/4.13.html (Current 20/05/2003)
44 INSTALLING:
46 1. Get a Word Processor - Abiword is mine. A hint is there, and it 
47 worked for me. If it doesn't work for you, argue with him, not me. 
49 If  you haven't done anything right yet, build abiword first. It has
50 loads of nice fonts which you can include in ghostscript by adding
51 '--with-fontpath=/usr/local/share/AbiSuite/fonts' to the gs
52 './configure'.  Otherwise see below.
55 2. Get ghostscript. I used espgs-7.05. There's all sorts of patches if
56 you want to go with gnu ghostscript, and AFAIK, Version 8 doesn't
57 compile for those who have tried it.
59 I won't bore you further on this. There is a ghostscript hint.From my 
60 inspection the gimp printer drivers for ghostscript seem to offer more 
61 promise than the cups ones. So a good set of options for ghostscript 
62 might include the following
63 ./configure --with-drivers=all --with-cups --with-gimp --with-fontpath=<etc>
65 If you don't have cups or gimp - that's fine. Lie through your teeth ;-)
67 This completes necessary installing. Easy, wasn't it?
69 CONFIGURING:
71 3. Type gs -h at a prompt and select your printer from the pageful of
72 drivers that it gives up. I have a BJC-4000 (bjc600 driver), but like a
73 true cheapskate, I use b/w cartridges, so bjcmono suits me. The bjc600
74 driver performs poorly, giving colour to a b/w printer. You may then
75 want to fire up vim and edit the ppd slightly.
77 vim /usr/local/share/ghostscript-7.05/filter/bjcmono.ppd
79 or whatever your ghostscript /filter directory is. Don't muck it up,
80 just change defaults to another blindingly obvious option. If you
81 screw up completely, delete and you can do another 'make install'.
82 Test this driver by executing the following commands from a console.
84 gs -q -dBATCH -dNOPAUSE -dSAFER -sDEVICE=<your-printer-driver>  \
85 -sOutputFile=/tmp/testit  <some_file.ps> .
87 There are good postscript files in the <ghostscript source>/examples
88 directory.  Give it a few seconds. Make sure your printer is on.
89 Follow this with
91 cat /tmp/testit > /dev/lp0
93 or whatever point in the /dev directory your printer resides in. Paper
94 & ink should flow relatively productively. If you get a ghostscript
95 crash, look for a wordlike 'invalidfileaccess' (file error) as a hint
96 to what went wrong. If you can see the file but not send it to
97 print,have you permission? If so,  it's your '-sDEVICE=' option or a
98 syntax error.
100 If you fall over trying to write to /tmp as a user, execute (as root)
102 chmod 1777 /tmp 
104 and kick yourself for being too security conscious.
106 To save paper - less /tmp/testit
108 should show you a binary file full of gibberish. Perfect!  If you see
109 text, you've got problems. The details after ' -sOutputFile=' can be
110 any filename.  -sOutputFile=/home/your_dir/rude_word would work just as
111 well. Those options mean: 
113 -q - tells gs not to display anything & saves it looking for X.
115 -dBATCH - tells gs to quit after processing - always a good idea.
117 -dNOPAUSE - gs will not wait for a keypress.
119 -dSAFER -   stops gs from  deleting or zapping anything.
121 -sDEVICE= your printer driver. Be exact and case sensitive. GS is
122 stupid.Use the spelling on the info at 'gs -h'.
124 -r360 - tells the resolution to use. You may not need this. You hacked
125 the ppd, remember? Yours may be different. It's the dpi.
127 -sOutputFile= write to this output file (congratulations for guessing!)
128 Brew your own cocktail of these options. Refine & remember it, or write
129 it down. 'Man gs' is instructive.
131 -sPAPERSIZE= (if I have to tell you this....).
133 An added refinement is to review the gs -h info. At the end it
134 mentions a number of places where ghostscript checks for fonts.
135 Let one of them symlink to wherever abiword hid it's selection
136 (/usr/local/share/AbiSuite/fonts on my system), so ghostscript can
137 tap in, in the vain hope that you might get a WYSIWYG word processor.
138 It might even work.
141 3. Skip this if you are opting for the a2ps option for multipage ascii. 
142 You should also be able to print text with 'cat > /dev/lp0' or
143 wherever your printer is. I found I needed a few lines on top of the
144 page with cat as my printing tool.  I got them the lazy way vim
145 /tmp/header. It says "new file"; hit insert, return 3 times, escape,
146 and :wq. You should have a /tmp/header file with three blank lines ;-)
148 An alias  in etc/profile to get it out to the printer
150 alias print='cat  /tmp/header  /tmp/testit  >  /dev/lp0'
152 This sends my file /tmp/testit to the printer after /tmp/header.
153 Log out & in to get the alias recognised. Type alias and see if print
154 is actually one of the ones listed
156 Usage: print <filename>or cat /tmp/header <textfile> >/dev/lp0
159 A hidden gotcha is that multipage ascii docs will mess up by
160 missing headers and often a few lines between pages. Load them in
161 abiword, or any wp that will print to a .ps file, and that will sort
162 them neatly into pages. Go around & set defaults to your paper size.
163 Uli's script (section 10) ideally needs a text section to send a 
164 header at the top of each page of ascii. If you can dream it up,  
165 script it and send it to me for inclusion. You, of course, will get 
166 credited, and a2ps will come out.
169 4. Some tidying up :-D.  Use 'make uninstall' targets on your
170 "printing" programs if they exist. Then, if cups
171 has you seriously browned off (like it has me), for example
173         rm -rf /etc/cups
174         rm -rf /usr/share/cups
175         rm -rf /var/spool/cups
176         rm -rf /usr/src/cups*
177         rm  -rf /usr/share/docs/cups
179 All those unnecessary files in the /usr/bin & /usr/local/bin
180 directories; broken loser program to do what we are doing: gsbj; gsdj;
181 gsdj500; gslp; lp; lpr; lpd; lpadmin; lpstat, and probably lp*. You get
182 the  idea.  Have fun, and don't come crying to me if you mess up by
183 overdoing it. You can always reinstall, and reconfigure. It's your
184 system. You're the boss. I suggest you choose a directory for print
185 files - NOT /home/you/followed/by/a/long/directory/name but /tmp. You
186 can then add a
188 rm -f /tmp/*.ps
190 to some startup or shutdown file to clean up printed matter on a
191 reboot.. If you're fussy & security conscious,
192 make that something fussy & secure like
194 rm -i /tmp/*.ps and play God with these files.
196 Note that we got to here without a huge amount of the formatters and 
197 translators that seem to gather around inferior print strategies. Sad 
198 to say, few of these have 'make uninstall' targets, but such could be 
199 manufactured by attacking the Makefile :-D. 
202 5. If your docs have appearance problems, be aware that there are a
203 useful set of help documents in the .abw format which come with the
204 abiword source tree which AFAIK are not installed anywhere. These are
205 in the ~/abi/docs/ subdirectory.  They give details of how to load
206 windoze fonts, as well as the the best and most logical explanation of
207 the tortured intricasies of the Unix font and locale systems that I
208 have come across in some time. The abiword source is worth downloading
209 for these alone, even if you hate the thing. Unfortunately, in real M$
210 style, they are in abiword's individual .abw format. 
212 6. The first versions of this hint contained an appeal to savants for a 
213 printing script to automate this.
215 This script below (name it lpr locally) takes a .ps or .pdf file and
216 spits it at the printer, something printer programs seem to find
217 difficulty with ;-). Uli Fahrenberg <uli@math.auc.dk> contributed this,
218 and we bow and scrape in his general direction :-).
220 Before you say it doesn't work, revisit point 4 and make sure you
221 cleared all the other lpr programs out of the path. Install it
222 somewhewre in the path and chmod it to 755. 
224 Next, open lpr in your favourite editor. You may need to hack it.
226         1. Line 6 - DEVICE=<your printer driver>. Set now as ljet4
227         2. Line 7 - LP=<your printer port> without the '/dev/' bit
228         3. Lines 33, 43. If your paper isn't a4, edit it's size here
230 Usage is simple: it IS lpr, and does everything a 500K binary should:
231 Print from the 'print' function in any program, or call it from  a
232 command line or script. At a stroke we have obsoleted megabytes of 
233 bloated crap associated with printing. More Power to you, Uli!
235 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
236 #!/bin/bash
237 # By Uli Fahrenberg <uli@math.auc.dk>
238 # Check the arguments to gs suit your printer
241 DEVICE=ljet4    ## Your printer driver from 'gs -h' here
242 LP=lp0          ## Your printer port 
245 # Prints file to $DEVICE (above) connected at /dev/$LP(any port as above)
246 # Usage:        `lpr <ps or pdf file>' or `cat bla.ps | lpr'
247                 Or Print from any application to lpr.
248                 
250 if [ -e /tmp/.lp-lock ] ; then
251                 echo "Error: printer is locked  (/tmp/.lp-lock exists)"
252                 exit 1
253         fi
254 FILE=$1
255 if ! [ X$FILE = X ] ; then ### We have a filename as an argument.
256         if ! [ -r $FILE ] ; then
257                 echo "Error: Cannot read file $FILE"
258                 exit 1
259         fi
261 FTYPE=$(file -b $FILE | awk '{print $1}')
262         if ! [ $FTYPE = 'PDF' ] && ! [ $FTYPE = 'PostScript' ] ; then
263                 echo "Error: $FILE should be a PS or PDF file."
264                 exit 1
265         fi
266                 echo -n "Printing $FILE... "
267                 (touch /tmp/.lp-lock;\
268         gs -q -dBATCH -dNOPAUSE -dSAFER -sDEVICE=$DEVICE \
269                 -sPAPERSIZE=a4 -sOutputFile=- $FILE > /dev/$LP ; \
270                 rm /tmp/.lp-lock) & echo "Done."
272 else ### We are part of a pipe.
273         DATA="$(</dev/stdin)"
274         (touch /tmp/.lp-lock;\
275         echo "$DATA" \
276         | gs -q -dBATCH -dNOPAUSE -dSAFER -sDEVICE=$DEVICE \
277         -sPAPERSIZE=a4 -sOutputFile=- - \
278         > /dev/$LP;\
279         rm /tmp/.lp-lock)&
281 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
282 And to you, the reader: You should now be printing! 
283 If you want printing by users,  chmod 666 /dev/lp0
284 Also revisit the permissions of lpr (755), and gs (751)
286 7. Programmers and others like hint maintainers may have a need for
287 multipage ascii documents. As a concession to their needs, we cover
288 installing another program, a2ps. This is against the minimalist,
289 'delete all the crap' philosophy of this hint, but I weakened.
291 Install is the usual ./configure && make && make install. If you don't
292 like the /usr/local/etc location give it a --sysconfdir instruction on
293 the configure. 
295 A2ps has as many options as pppd :-(. If that wasn't bad enough, most
296 of them have long and short versions. He takes it for granted we all
297 know C :-/.Hack the config file and you can forget them. Here is how.
299 cp /usr/local/etc/a2ps.cfg /usr/local/etc/a2ps.cfg.orig just in case.
301 Install something like this as  /usr/local/etc/a2ps.cfg. I shortened
302 the original considerably but left it's sections intact, so you could
303 find things in it.
305 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
306 # -*- ksh -*-
307 # a2psrc
309 #################################################################
310 # 1)            Definition of some media                        #
311 # (Must be defined before --medium)                             #
312 #################################################################
313 # Medium: name, width height [llx lly urx ury]
314 Medium: A3       842    1190
315 Medium: A4       595     800
316 Medium: A5       420     595
317 Medium: B4       729    1032
318 Medium: B5       516     729
319 Medium: Letter   612     792
320 Medium: Legal    612    1008
321 Medium: Tabloid  792    1224
322 Medium: Ledger  1224     792
323 Medium: Statement 396    612
324 Medium: Executive 540     720
325 Medium: Folio    612     936
326 Medium: Quarto   610     780
327 Medium: 10x14    720    1008
329 # Desk Jet users: bigger margins
330 #       Also bigger ink cartridge bills :-D 
332 #################################################################
333 # 2)    Path to the a2ps resource                               #
334 #################################################################
335 # Default path where a2ps dropped its library files.
336 LibraryPath: /usr/local/share/a2ps/sheets:/usr/local/share/a2ps/ps:/usr/
337 local/share/a2ps/encoding:/usr/local/share/a2ps/afm:/usr/local/share/a2p
338 s/ppd:/usr/local/share/a2ps/fonts:/usr/local/share/a2ps
341 #################################################################
342 # 3)    System dependant parameters                             #
343 #################################################################
344 # By default, produce Level 1 PostScript.
345 # Currently it only means to consider only the 13 level 1 standard
346 # fonts, and not the 35 standard level 2 fonts.
347 DefaultPPD: level2
349 # First, the default printer (option -d, no argument)
350 DefaultPrinter: | lpr
353 # Second, a printer unkown to a2ps (option -P, argument is #o)
354 UnknownPrinter: | lpr
356 # Then, special printers you might want to define.
357 # Here, dominique is a Level 2 PostScript printer
358 # Printer: dominique level2 | lp -d dominique
360 # Default encoding
361 Options: --encoding=latin1
363 # Default medium
364 Options: --medium=A4
366 Options: --lines-per-page=60
369 # How to call file(1), and if possible, follow the links
370 FileCommand: /usr/bin/file -L
373 #################################################################
374 # 4)    Your printers                                           #
375 #################################################################
377 #################################################################
378 # 5)    Default settings                                        #
379 #################################################################
380 # Two virtual pages per sheet.
381 Options: -1
383 # Set automatic pretty-printing on (set to "plain" for off)
384 Options: --pretty-print
386 # By default, single sided printing
387 Options: -s1
389 # Name of the document is the list of files
390 # (Don't put too many of them: it breaks some PS interpreters)
391 # ptions: '--title=#10!f|$n|, |'
393 # Header is the client of the job
394 # Options: --header=%a
396 # Title of the page is the (short) name of the current file
397 # or the first taged text if there is
398 Options: --center-title=#?1|$t1|$n|
400 # Left part of the title is the mod. date of the file
401 # or empty is there is a tag2
402 Options: '--left-title=#?2||$e $T|'
404 # Right part of the title is the page number
405 # or tag2 if there is
406 Options: '--right-title=#?2|$t2|$Q|'
408 # If in landscape, print date on the left hand side
409 # If portrait, then print date on recto, and sheet # on verso
410 Options: --left-footer=#?l!%E!#?v|%E|%s./%s#|!
412 # Center footer is the list of files on this sheet if landscape
413 # Options: '--footer=#?l|#!s-$f-, -||'
415 # If in landscape, print date on the right hand side
416 # If portrait, then print date on verso, and sheet # on recto
417 # Options: --right-footer=#?l!%s./%s#!#?v|%s./%s#|%E|!
419 # We want the %%Page comments to be instructive.
420 # There are two predefined choices: #{pl.short} and #{pl.long}
421 PageLabelFormat: #{pl.short}
424 #################################################################
425 # 6)    Preconfigured Macro Meta Sequences                      #
426 #################################################################
428 # Some Macros for the delegations
429 #       Strictly for the ambitious!
431 #################################################################
432 # 7)    Preconfigured delegations                               #
433 #################################################################
435 # Delegations are ways to hand off the processing of some
436 # files to other filters.
437 #        What other filters? 
439 #################################################################
440 # 8)    Some interesting UserOptions/Printers                   #
441 #################################################################
443 #               Yeah... Right!
445 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
447 Trim out my nauseous disrespectful comments, and insert your own more 
448 pointed and caustic humour.Interesting things to note are: (Section 
449 numbers in Brackets)
451 (1)Medium: A4       595     800. 
453 This is shorter than the 840 in the original, as I found it ran off the
454 page and dirtied the second and subsequent pages.
456 (3)DefaultPrinter: | lpr
458 (3)Options: --lines-per-page=58
460 Default printer pipes to the lpr script. I inserted the lines per page
461 to tweak down the length, as my printer default font is bigger than
462 a2ps thinks it is. The config file apparently takes any of the long
463 options as shown on the man page. The header/footer stuff is in Section
464 5 and I don't understand a word of it. (It seems patterned on the
465 twisted thinking  typical of sed expressions).
467 With this, I can simply type
469 a2ps <textfile>
471 And I get a neat header, side borders, and page numbers. It goes off 
472 through lpr,  which wakes up ghostscript, but then we set lpr up, 
473 didn't we? The header has date, title, and page numbers.
475 Stop the stopwatch, e-mail me with your grateful thanks, praise, and
476 offers of gifts:-), & Cc to Uli Fahrenberg for the script.
480         Declan Moriarty.