home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 13 / CDA13.ISO / DOC / HOWTO / OTHER_FO / SGML / PRINTIN0.GZ / Printing-HOWTO.sgml
Encoding:
SGML Document  |  1996-08-02  |  37.0 KB  |  970 lines

  1. <!doctype linuxdoc system>
  2.  
  3. <!--
  4.        pht.sgml,v 3.9 1996/07/25 18:55:33 gtaylor Rel
  5.  -->
  6.  
  7. <article>
  8. <title>The Linux Printing HOWTO
  9.  
  10. <author>Grant Taylor, <tt/<gtaylor+pht@picante.com>/
  11. <date>v3.9, 25 July 1996
  12.  
  13. <abstract>
  14. This is the Linux Printing HOWTO, a collection of information on how
  15. to generate, preview, print and fax anything under Linux (and other
  16. Unices in general).
  17. </abstract>
  18.  
  19. <toc>
  20.  
  21. <sect>Intro
  22. <p>
  23. Since this is a complete rewrite, much information from previous
  24. editions has been lost.  This is by design, as the previous HOWTOs
  25. were so large as to be 60 typeset pages, and had the narrative flow of
  26. a dead turtle.  If you do not find the answer here, you are encouraged
  27. to a) scan the previous version at <url
  28. url="http://www.picante.com/~gtaylor/pht/" name="The PHT Home Page">
  29. and b) drop me a note saying what ought to be here but isn't.
  30. <p>
  31. The <url name="Printing HOWTO Home Page"
  32. url="http://www.picante.com/~gtaylor/pht/"> is a good place to find
  33. the latest version; it is also, of course, distributed from SunSite
  34. (<tt/sunsite.unc.edu/) and your friendly local LDP mirror.
  35.  
  36. <sect1>History
  37. <p>
  38. This is the third generation, which is to say the third complete
  39. rewrite, of the Printing HOWTO.  The history of the PHT may be
  40. chronicled thusly:
  41. <enum>
  42. <item>I wrote the printing-howto in response to too many printing
  43.       questions in comp.os.linux, and posted it.  This predated the
  44.       HOWTO project by a few months and was thus the first FAQlet
  45.       called a `howto'.  This edition was in plain ascii.
  46.  
  47. <item>After joining the HOWTO project, the Printing-HOWTO was merged
  48.       with an Lpd FAQ by Brian McCauley <tt/<B.A.McCauley@bham.ac.uk>/; we
  49.       continued to co-author
  50.       the PHT for two years or so.  At some point we incorporated the
  51.       work of Karl Auer <tt/<Karl.Auer@anu.edu.au>/.  This
  52.       generation of the PHT was in
  53.       TeXinfo, and available in PS, HTML, Ascii, and Info.  
  54.  
  55. <item>After letting the PHT rot and decay for over a year, and an
  56.       unsuccessful attempt at getting someone else to maintain it,
  57.       this rewrite happened.  This generation of the PHT is in
  58.       Linuxdoc-SGML.
  59. </enum>
  60. <sect1>Copyright
  61. <p>
  62. This document is Copyright (c) 1996 by Grant Taylor.  Please copy and
  63. distribute it widely, but do not modify the text or omit my name.
  64. <sect>How to print
  65. <p>
  66. If you've already got lpd setup to print to your printer, or your
  67. system administrator already did so, or your vendor did so for you,
  68. then all you need to do is learn how to use the lpr command.  The <url
  69. name="Printing Usage HOWTO"
  70. url="http://sunsite.unc.edu/mdw/HOWTO/Printing-Usage-HOWTO.html"> covers
  71. this, and a few other queue manipulation commands you should probably
  72. know.
  73.  
  74. <sect>Kernel printer devices
  75. <sect1>The lp device
  76. <p>
  77. The Linux kernel, assuming you have compiled in or loaded the lp
  78. device (the output of <tt>cat /proc/devices</tt> should include the
  79. device lp), provides one or more of <em>/dev/lp0</em>,
  80. <em>/dev/lp1</em>, and <em>/dev/lp2</em>.  These are NOT assigned
  81. dynamically, rather, each corresponds to a specific hardware I/O
  82. address.  This means that your first printer may be <em/lp0/ or
  83. <em/lp1/ depending on your hardware.  Try both ;)
  84. <p>
  85. One cannot run the plip and lp drivers at the same time on any given
  86. port.  You can, however, have one or the other driver loaded at any
  87. given time either manually, or by kerneld with v2 (and later 1.3.x)
  88. kernels.  By carefully setting the interrupts and such, you can
  89. supposedly run plip on one port and lp on the other.  One person did
  90. so by editing the drivers; I eagerly await a success report of someone
  91. doing so with only a clever command line.
  92. <p>
  93. There is a little utility called <tt><htmlurl
  94. url="http://www.picante.com/~gtaylor/pht/man/tunelp.html"
  95. name="tunelp"></tt> floating about with which you, as root, can tune
  96. the Linux lp device's interrupt usage, polling rate, and other
  97. options.
  98. <p>
  99. When built in to some 1.3.x and v2 kernels, the kernel will accept an
  100. <tt>lp=</tt> option to set interrupts and io addresses:
  101. <tscreen><verb>
  102. When the lp driver is built in to the kernel, you may use the
  103. LILO/LOADLIN command line to set the port addresses and interrupts
  104. that the driver will use.
  105.  
  106. Syntax:      lp=port0[,irq0[,port1[,irq1[,port2[,irq2]]]]]
  107.  
  108. For example:   lp=0x378,0   or   lp=0x278,5,0x378,7 **
  109.  
  110. Note that if this feature is used, you must specify *all* the ports
  111. you want considered, there are no defaults.  You can disable a
  112. built-in driver with lp=0.
  113. </verb></tscreen>
  114. <p>
  115. When loaded as a module in version 2 and late-model 1.3.x kernels, it
  116. is possible to specify io addresses and interrupt lines on the insmod
  117. command line (or in <em>/etc/conf.modules</em> so as to affect
  118. kerneld) using the usual syntax.  The parameters are
  119. <tt/io=port0,port1,port2/ and <tt/irq=irq0,irq1,irq2/.  Read ye the
  120. man page for <em/insmod/ for more information on this.  
  121.  
  122. <p>
  123. **For those of you who (like me) can never find the standard port
  124. numbers when you need them, they are as in the second example above.
  125. The other port (<em/lp0/) is at 0x3bc.  I've no idea what interrupt it
  126. usually uses.
  127.  
  128. <sect1>Serial devices
  129. <p>
  130. Serial devices are usually called something like <em>/dev/ttyS1</em>
  131. under Linux.  The utility <tt><htmlurl
  132. url="http://www.picante.com/~gtaylor/pht/man/stty.html"
  133. name="stty"></tt> will allow you to interactively view or set the
  134. settings for a serial port; <tt><htmlurl name="setserial"
  135. url="http://www.picante.com/~gtaylor/pht/man/setserial.html"></tt>
  136. will allow you to control a few extended attributes and configure IRQs
  137. and I/O addresses for non-standard ports.  Further discussion of
  138. serial ports under Linux may be found in the <url
  139. url="http://sunsite.unc.edu/mdw/HOWTO/Serial-HOWTO.html"
  140. name="Serial-HOWTO">.
  141.  
  142. <sect>How it works, basic
  143. <p>
  144.  
  145. In order to get printing working well, you need to understand how the
  146. lpd system works.
  147. <p>
  148. Lpd stands for Line Printer Daemon, and refers in different contexts
  149. to both the daemon and the whole collection of programs which run
  150. print spooling.  These are:
  151. <p>
  152. <descrip>
  153. <tag><tt><htmlurl name="lpd" url="http://www.picante.com/~gtaylor/pht/man/lpd.html"></tt></tag>The spooling daemon.  One of these runs to control
  154.                        everything on a machine, AND one is run per
  155.                        printer while the printer is printing. 
  156. <tag><tt><htmlurl name="lpr" url="http://www.picante.com/~gtaylor/pht/man/lpr.html"></tt></tag>The user spooling command.  Lpr contacts lpd
  157.                        and injects a new print job into the spool.
  158. <tag><tt><htmlurl name="lpq" url="http://www.picante.com/~gtaylor/pht/man/lpq.html"></tt></tag>Lists the jobs in a print queue.
  159. <tag><tt><htmlurl name="lpc" url="http://www.picante.com/~gtaylor/pht/man/lpc.html"></tt></tag>The Lpd system control command.  With lpc you
  160.                        can stop, start, reorder, etc, the print queues.
  161. <tag><tt><htmlurl name="lprm" url="http://www.picante.com/~gtaylor/pht/man/lprm.html"></tt></tag><tt/lprm/ will remove a job from the print spool.
  162. </descrip>
  163. <p>
  164. So how does it fit together?  Well, when the system boots, lpd is
  165. run.  It scans the file <em>/etc/printcap</em> to learn which printers
  166. it will be managing spools for.  Each time someone runs lpr, lpr
  167. contacts lpd through the named socket <em>/dev/printer</em>, and feeds
  168. lpd both the file to print and some information about who is printing
  169. and how to print it.  Lpd then prints the file on the appropriate
  170. printer in turn.
  171. <p>
  172. The lp system was originally designed when most printers were line
  173. printers - that is, people mostly printed plain ascii.  As it turns
  174. out, only a little extra scripting is needed to make lpd work quite
  175. well for today's print jobs, which are often in PostScript, or text,
  176. or dvi, or...
  177.  
  178. <sect>How to set things up, basic
  179. <sect1>Traditional lpd configuration
  180. <p>
  181. The minimal setup for lpd rsults in a system that can queue files and
  182. print them.  It will not pay any attention to wether or not your
  183. printer will understand them, and will probably not let you produce
  184. attractive output.  Nevertheless, it is the first step to
  185. understanding, so read on!
  186. <p>
  187. Basically, to add a print queue to lpd, you must add an entry in
  188. <em>/etc/printcap</em>, and make the new spool directory under
  189. <em>/var/spool/lpd</em>.
  190. <p>
  191. An entry in <em>/etc/printcap</em> looks like:
  192. <tscreen><verb>
  193. # LOCAL djet500
  194. lp|dj|deskjet:\
  195.     :sd=/var/spool/lpd/dj:\
  196.     :mx#0:\
  197.     :lp=/dev/lp0:\
  198.     :sh:
  199. </verb></tscreen>
  200. This defines a spool called <em/lp/, <em/dj/, or <em/deskjet/, spooled
  201. in the directory <em>/var/spool/lpd/dj</em>, with no per-job maximum size
  202. limit, which prints to the device <em>/dev/lp0</em>, and which does
  203. not have a
  204. banner page (with the name of the person who printed, etc)
  205. added to the front of the print job.
  206. <p>
  207. Go now and read the man page for <em><htmlurl name="printcap" url="http://www.picante.com/~gtaylor/pht/man/printcap.html"></em>.
  208. <p>
  209. The above looks very simple, but there a catch - unless I send in
  210. files a DeskJet 500 can understand, this DeskJet will print strange
  211. things.  For example, sending an ordinary Unix text file to a deskjet
  212. results in literally interpreted newlines, and gets me:
  213. <tscreen><verb>
  214. This is line one.
  215.                  This is line two.
  216.                                   This is line three.
  217. </verb></tscreen>
  218. ad nauseum.  Printing a PostScript file to this spool would get a
  219. beautiful listing of the PostScript commands, printed out with this
  220. "staircase effect", but no useful output.
  221. <p>
  222. Clearly more is needed, and this is the purpose of filtering.  The
  223. more observant of you who read the printcap man page might have
  224. noticed the spool attributes <em/if/ and <em/of/.  Well, <em/if/, or
  225. the input filter, is just what we need here.
  226. <p>
  227. If we write a small shell script called <em/filter/ that adds carriage
  228. returns before newlines, the staircasing can be eliminated.  So we
  229. have to add in an <em/if/ line to our printcap entry above:
  230. <tscreen><verb>
  231. lp|dj|deskjet:\
  232.     :sd=/var/spool/lpd/dj:\
  233.     :mx#0:\
  234.     :lp=/dev/lp0:\
  235.     :if=/var/spool/lpd/dj/filter:\
  236.     :sh:
  237. </verb></tscreen>
  238. A simple filter script might be:
  239. <tscreen><verb>
  240. #!perl
  241. while(<STDIN>){chop $_; print "$_\r\n";};
  242. </verb></tscreen>
  243. If we were to do the above, we'd have a spool to which we could print
  244. regular Unix text files and get meaningful results.  (Yes, there are
  245. four million better ways to write this filter, but few so
  246. illustrative.  You are encouraged to do this more efficiently.)
  247. <p>
  248. The only remaining problem is that printing plain text is really not
  249. too hot - surely it would be better to be able to print PostScript and
  250. other formatted or graphic types of output.  Well, yes, it would, and
  251. it's easy to do.  The method is simply an extention of the above
  252. linefeed-fixing filter.  If you write a filter than can accept
  253. arbitrary file types as input and produce DeskJet-kosher output for
  254. each case, then you've got a clever print spooler indeed!
  255. <p>
  256. Such a filter is called a <em/magic/ filter.  Don't bother writing one
  257. yourself unless you print strange things - there are a good many
  258. written for you already on the net.
  259.  
  260. <sect1>File Permissions
  261. <p>
  262. By popular demand, I include below a listing of the permissions on
  263. interesting files on my system.  There are a number of better ways to
  264. do this, ideally using only SGID binaries and not making everything
  265. SUID root, but this is how my system came out of the box, and it works
  266. for me.  (Quite frankly, if your vendor can't even ship a working lpd
  267. you're in for a rough ride).
  268. <tscreen><verb>
  269. -r-sr-sr-x   1 root     lp    /usr/bin/lpr*
  270. -r-sr-sr-x   1 root     lp    /usr/bin/lprm*
  271. -rwxr--r--   1 root     root  /usr/sbin/lpd*
  272. -r-xr-sr-x   1 root     lp    /usr/sbin/lpc*
  273. drwxrwxr-x   4 root     lp    /var/spool/lpd/
  274. drwxr-xr-x   2 root     lp    /var/spool/lpd/lp/
  275. </verb></tscreen>
  276. <p>
  277. Lpd must currently be run as root so that it can bind to the
  278. low-numbered lp service port.  It should probably become UID lp.lp
  279. or something after binding, but I don't think it does.  Bummer.
  280.  
  281. <sect>How to obtain an appropriate magic filter
  282.  
  283. <sect1>APS Filter
  284. <p>
  285. One of the nicest magic filter packages is aps filter, by Andreas
  286. Klemm.  The Linux Software Map entry goes something like this:
  287. <tscreen><verb>
  288. Begin3
  289. Title:        apsfilter
  290. Version:    4.9.1
  291. Entered-date:    Montag, 10. Juli 1995, 21:22:35 Uhr MET DST
  292. Description:    magicfilter for lpd with auto filetype detection
  293. Keywords:    lpd magicfilter aps apsfilter
  294. Author:     andreas@knobel.GUN.de (Andreas Klemm)
  295. Maintained-by:    sledge@hammer.oche.de (Thomas Bueschgens)
  296.         andreas@knobel.GUN.de (Andreas Klemm)
  297. Primary-site:    sunsite.unc.edu
  298.         /pub/Linux/system/Printing/
  299.         211KB aps-491.tgz
  300. Original-site:    ftp-i2.informatik.rwth-aachen.de
  301.         /pub/Linux/pak/APSfilter/aps-491.tgz
  302. Platforms:    C-Compiler, gs Postscript emulator, pbmutils
  303. Copying-policy:    GPL
  304. End
  305. </verb></tscreen>
  306. APS filter installs as an <em/if/ filter for a print queue, and will
  307. translate from many common file types into your printer's command
  308. set.  It understands, for example, text, PostScript, dvi, gif, and
  309. others.
  310.  
  311. <sect1>Magic-filter
  312. <p>
  313. The magic-filter package, written by B.A.McCawley, works much the same
  314. way as does APSfilter, but since it is written in bash, it might be
  315. more easy to customize.  The LSM entry:
  316. <tscreen><verb>
  317. Version: 0.4 
  318. Description: Bash scripts to simplify the task of configuring lpd to
  319.    auto-detect file types using /etc/magic. (As advertised in the
  320.    printing-HOWTO).
  321.    This package uses existing filters so it only prints file types for
  322.    which one already has filters (or compressed versions
  323.    thereof). Alterative magic filter approches are described in the
  324.    printing-HOWTO.
  325. Keywords: lpd, /etc/magic, printing, filter
  326. Author: B.A.McCauley@bham.ac.uk (Brian McCauley)
  327. Maintained-by: B.A.McCauley@bham.ac.uk
  328. Primary-site: tsx-11.mit.edu pub/linux/sources/usr.bin
  329.               magic-filter-0.4.tar.gz  5709
  330. Copying-policy: GNU GPL
  331. </verb></tscreen>
  332.  
  333. <sect1>The other Magicfilter
  334. <p>
  335. For maximum confusion, there appear to be two packages named just
  336. magic filter out there.  (Or are they the same?)
  337. <tscreen><verb>
  338. Title:          magicfilter
  339. Version:        1.1b
  340. Entered-date:   04APR95
  341. Description:    A customizable, extensible automatic printer filter.
  342.                 Lets you automatically detect and print just about any
  343.                 data type you can find a conversion utility for.  This
  344.                 filter is written in C and is controlled completely
  345.                 from an external printer configuration file.
  346.                 This version adds automagic creation of configuration
  347.                 files based on the installed software on your system,
  348.                 courtesy of GNU Autoconf.
  349.                 This version is a bug fix from 1.1/1.1a; filters for
  350.                 non-ASCII capable PostScript printers have been added.
  351. Author:         H. Peter Anvin <Peter.Anvin@linux.org>
  352. Primary-site:   sunsite.unc.edu
  353.                 53000 /pub/Linux/system/Printing/magicfilter-1.1b.tar.gz
  354. Copying-policy: GPL
  355. </verb></tscreen>
  356.  
  357. <sect>Serial printers under lpd
  358. <sect1>Setting up in printcap
  359. <p>
  360. Lpd provides five attributes which you can set in
  361. <em>/etc/printcap</em> to control all the settings of the serial port
  362. a printer is on.  Read the <em><htmlurl name="printcap"
  363. url="http://www.picante.com/~gtaylor/pht/man/printcap.html"></em> man
  364. page and note the meanings of <em/br#/, <em/fc#/,
  365. <em/xc#/, <em/fs#/ and <em/xs#/.  The last four of these
  366. attributes are bitmaps indicating the settings for use the port.  The
  367. <em/br#/ atrribute is simply the baud rate, ie `<tt/br#9600/'.
  368.  
  369. <p>
  370. It is very easy to translate from <htmlurl name="stty"
  371. url="http://www.picante.com/~gtaylor/pht/man/stty.html"> settings to
  372. printcap flag settings. If you need to, see the man page for stty now.
  373.  
  374. <p>
  375. Use stty to set up the printer port so that you can cat a file to it
  376. and have it print correctly. Here's what `<em/stty -a/' looks like for my
  377. printer port:
  378. <tscreen><verb>
  379. dina:/usr/users/andy/work/lpd/lpd# stty -a < /dev/ttyS2
  380. speed 9600 baud; rows 0; columns 0; line = 0;
  381. intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>;
  382. eol2 = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W;
  383. lnext = ^V; min = 1; time = 0;
  384. -parenb -parodd cs8 hupcl -cstopb cread -clocal -crtscts
  385. -ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr 
  386. -igncr -icrnl ixon -ixoff -iuclc -ixany -imaxbel
  387. -opost -olcuc -ocrnl -onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 
  388. bs0 vt0 ff0
  389. -isig -icanon -iexten -echo -echoe -echok -echonl -noflsh -xcase
  390. -tostop -echoprt -echoctl -echoke
  391. </verb></tscreen>
  392. The only changes between this and the way the port is initialized at
  393. bootup are <tt/-clocal/, <tt/-crtscts/, and <tt/ixon/. Your port may
  394. well be different depending on how your printer does flow control.
  395.  
  396. <p>
  397. You actually use stty in a somewhat odd way.  Since stty operates on
  398. the terminal connected to it's standard input, you use it to
  399. manipulate a given serial port by using the `<tt/</' character as
  400. above.
  401.  
  402. <p>
  403. Once you have your stty settings right, so that `<em>cat file >
  404. /dev/ttyS2</em>' (in my case) sends the file to the printer, look at
  405. the file /usr/src/linux/include/linux/termios.h. This contains a lot
  406. of #defines and a few structs (You may wish to cat this file to the
  407. printer (you do have that working, right?) and use it as scratch
  408. paper).  Go to the section that starts out
  409.  
  410. <tscreen><verb>
  411. /* c_cflag bit meaning */
  412. #define CBAUD   0000017
  413. </verb></tscreen>
  414. This section lists the meaning of the <em/fc#/ and <em/fs#/ bits. You
  415. will notice that the names there (after the baud rates) match up with
  416. one of the lines of stty output. Didn't I say this was going to be
  417. easy?
  418.  
  419. <p>
  420. Note which of those settings are preceded with a - in your stty
  421. output. Sum up all those numbers (they are octal). This represents the
  422. bits you want to clear, so the result is your <em/fc#/ capability.  Of
  423. course, remember that you will be setting bits directly after you
  424. clear, so you can just use `<tt/fc#0177777/' (I do).
  425.  
  426. <p>
  427. Now do the same for those settings (listed in this section) which do
  428. not have a - before them in your stty output. In my example the
  429. important ones are CS8 (0000060), HUPCL (0002000), and CREAD
  430. (0000200). Also note the flags for your baud rate (mine is
  431. 0000015). Add those all up, and in my example you get 0002275. This
  432. goes in your <em/fs#/ capability (`<tt/fs#02275/' works fine in my
  433. example).
  434.  
  435. <p>
  436. Do the same with set and clear for the next section of the include
  437. file, "c_lflag bits". In my case I didn't have to set anything, so I
  438. just use `<tt/xc#0157777/' and `<tt/xs#0/'.
  439.  
  440. <sect1>Older serial printers that drop characters
  441. <p>
  442. Jon Luckey points out that some older serial printers with ten-cent
  443. serial interfaces and small buffers <em/really/ mean stop when they
  444. say so with flow control.  He found that disabling the FIFO in his
  445. Linux box's 16550 serial port with <tt><htmlurl name="setserial"
  446. url="http://www.picante.com/~gtaylor/pht/man/setserial.html"></tt>
  447. corrected the problem of dropped characters (you apparently just
  448. specify the uart type as an 8250 to do this).
  449.  
  450. <sect>Vendor Solutions
  451. <p>
  452. [ This section is, by definition, incomplete.  Feel free to send in
  453. details of your favourite distribution. ]
  454.  
  455. <sect1>RedHat 2.x
  456. <p>
  457. RedHat has a GUI printer administration tool which can add remote
  458. printers and printers on local devices.  It lets you choose a
  459. ghostscript-supported printer type and Unix device file to print to,
  460. then installs a print queue in <em>/etc/printcap</em> and writes a
  461. short PostScript-and-ascii magic filter based around <tt/gs/ and
  462. <tt><htmlurl name="nenscript"
  463. url="http://www.picante.com/~gtaylor/pht/man/nenscript.html"></tt>.
  464. This solution works fairly well, and is trivial to setup for common
  465. cases.
  466.  
  467. <sect1>Other Distributions
  468. <p>
  469. Please send me info on what other distributions do.
  470.  
  471. <sect>How to print to a printer over the network
  472. <p>
  473. One of the features of lpd is that it supports printing over the
  474. network to printers physically connected to a different machine.  With
  475. the careful combination of filter scripts and assorted utilities, you
  476. can make lpr print transparently to printers on all sorts of networks.
  477. <sect1>To a Unix/lpd host
  478. <p>
  479. To allow remote machines to print to your printer, you must list the
  480. machines in <em>/etc/hosts.equiv</em> or <em>/etc/hosts.lpd</em>.
  481. (Note that <em/hosts.equiv/ has a host of other effects; be sure you
  482. know what you are doing if you list any machine there).  You can allow
  483. only certain users on the other machines to print to your printer by
  484. usign the <em/rs/ attribute; read the <tt><htmlurl name="lpd"
  485. url="http://www.picante.com/~gtaylor/pht/man/lpd.html"></tt> man page
  486. for information on this.
  487.  
  488. <sect1>With <tt>lpd</tt>
  489. <p>
  490. To print to another machine, you make an <em>/etc/printcap</em> entry
  491. like this:
  492. <tscreen><verb>
  493. # REMOTE djet500
  494. lp|dj|deskjet:\
  495.     :sd=/var/spool/lpd/dj:\
  496.     :rm=machine.out.there.com:\
  497.     :rp=printername:\
  498.     :lp=/dev/null:\
  499.     :sh:
  500. </verb></tscreen>
  501. Note that there is still a spool directory on the local machine
  502. managed by <tt/lpd/.  If the remote machine is busy or offline, print
  503. jobs from the local machine wait in the spool area until they can be
  504. sent.
  505.  
  506. <sect1>With <tt>rlpr</tt>
  507. <p>
  508. You can also use <em>rlpr</em> to send a print job directly to a queue
  509. on a remote machine without going through the hassle of configuring
  510. lpd to handle it.  This is mostly useful in situations where you print
  511. to a variety of printers only occasionally.  From the announcement for
  512. <em>rlpr</em>:
  513.  
  514. <p>
  515. Rlpr uses TCP/IP to send print jobs to lpd servers anywhere on a
  516. network. 
  517.  
  518. <p>
  519. Unlike lpr, it *does not* require that the remote printers be
  520. explicitly known to the machine you wish to print from, (e.g. through
  521. <em>/etc/printcap</em>) and thus is considerably more flexible and
  522. requires less administration.
  523.  
  524. <p>
  525. rlpr can be used anywhere a traditional lpr might be used, and is
  526. backwards compatible with traditional BSD lpr.
  527.  
  528. <p>
  529. The main power gained by rlpr is the power to print remotely *from
  530. anywhere to anywhere* without regard for how the system you wish to
  531. print from was configured.  Can work as a filter just like traditional
  532. lpr so that clients executing on a remote machine like netscape,
  533. xemacs, etc, etc can print to your local machine with little effort.
  534.  
  535. <p>
  536. Rlpr is available from <tt><url name="SunSite"
  537. url="ftp://sunsite.unc.edu/pub/Linux/system/Printing/"></tt>.
  538.  
  539. <sect1>To a Win95, WinNT, LanManager, or Samba printer
  540. <p>
  541. It is possible to direct an lpd queue through the <tt><htmlurl
  542. name="smbclient"
  543. url="http://www.picante.com/~gtaylor/pht/man/smbclient.html"></tt>
  544. program (part of the samba suite) to a TCP/IP based SMB print service.
  545. Samba includes a script to do this called <tt/smbprint/.  In short,
  546. you put a configuration file for the specific printer in question in
  547. the spool directory, and install the <tt/smbprint/ script as the
  548. <em/if/.
  549. <p>
  550. The <em>/etc/printcap</em> entry goes like this:
  551. <tscreen><verb>
  552. lp|remote-smbprinter:\
  553.     :lp=/dev/null:sh:\
  554.     :sd=/var/spool/lpd/lp:\
  555.     :if=/usr/local/sbin/smbprint:
  556. </verb></tscreen>
  557. <p>
  558. You should read the documentation inside the <tt/smbprint/ script for
  559. more information on how to set this up.
  560. <p>
  561. You can also use <tt>smbclient</tt> to submit a file directly to an
  562. SMB printing service without involving <tt>lpd</tt>.  See the man page.
  563.  
  564. <sect1>To a NetWare Printer
  565. <p>
  566. The ncpfs suite includes a utility called <tt/nprint/ which provides
  567. the same functionality as <tt/smbprint/ but for NetWare.  You can get
  568. ncpfs from <url url="ftp://linux01.gwdg.de/pub/ncpfs/">.  From the
  569. LSM entry for version 0.16:
  570.  
  571. <quote>
  572. With ncpfs you can mount volumes of your netware server under
  573. Linux. You can also print to netware print queues and spool netware
  574. print queues to the Linux printing system. You need kernel 1.2.x or
  575. 1.3.54 and above. ncpfs does NOT work with any 1.3.x kernel below
  576. 1.3.54.
  577. </quote>
  578.  
  579. <p>
  580. To make <tt/nprint/ work via lpd, you write a little shell script to
  581. print stdin on the NetWare printer, and install that as the <em/if/
  582. for an lpd print queue.  You'll get something like:
  583. <tscreen><verb>
  584. sub2|remote-NWprinter:\
  585.     :lp=/dev/null:sh:\
  586.     :sd=/var/spool/lpd/sub2:\
  587.     :if=/var/spool/lpd/nprint-script:
  588. </verb></tscreen>
  589. The <tt>nprint-script</tt> might look approximately like:
  590. <tscreen><verb>
  591. #! /bin/sh
  592. /usr/local/bin/nprint -S net -U name -P passwd -q printq-q -
  593. </verb></tscreen>
  594.  
  595. <sect1>To an EtherTalk (Apple) printer
  596. <p>
  597. The netatalk package includes something like <tt/nprint/ and
  598. <tt/smbclient/.  Werner Eugster has documented the procedure for
  599. printing to and from an Apple network far better than I ever will; see
  600. his <url name="web page"
  601. url="http://garnet.berkeley.edu/~weugster/appleprint.html">.
  602. <p>
  603. Obscure caveat of the week: Netatalk does not work with SMC Etherpower
  604. PCI Card with a DEC tulip chip.
  605.  
  606. <sect1>To an HP or other ethernet printer
  607. <p>
  608. HPs and some other printers come with an ethernet interface which you
  609. can print to directly using lpd.  You should follow the instructions
  610. that came with your printer or its network adaptor, but in general,
  611. such printers are "running" lpd, and provide one or more queues which
  612. you can print to.  An HP, for example, might work with a printcap
  613. like:
  614. <tscreen><verb>
  615. lj-5|remote-hplj:\
  616.         :lp=/dev/null:sh:\
  617.         :sd=/var/spool/lpd/lj-5:\
  618.         :rm=printer.name.com:rp=raw:
  619. </verb></tscreen>
  620. <p>
  621. In a large scale environment, especially a large environment where
  622. some printers do not support PostScript, it may be useful to establish
  623. a dedicated print server to which all machines print and on which all
  624. ghostscript jobs are run.
  625.  
  626. <sect2>To older HPs
  627. <p>
  628. Some printers (and printer networking "black boxes") support only a
  629. cheesy little non-protocol involving plain TCP connections.  Notable
  630. in this category are early-model JetDirect (including some
  631. JetDirectEx) cards.  Basically, to print to the printer, you must open
  632. a TCP connection to the printer on a specified port (typically 9100)
  633. and stuff your print job into it.  This can be implemented, among
  634. other ways, in Perl:
  635.  
  636. <tscreen><verb>
  637. #!/usr/bin/perl
  638. # Thanks to Dan McLaughlin for writing the original version of this
  639. # script (And to Jim W. Jones for sitting next to Dan when writing me
  640. # for help ;)
  641.  
  642. $fileName = @ARGV[0];
  643.  
  644. open(IN,"$fileName") || die "Can't open file $fileName";
  645.  
  646. $dpi300     = "\x1B*t300R";
  647. $dosCr      = "\x1B&ero;k3G";
  648. $ends = "\x0A";
  649.  
  650. $port =  9100 unless $port;
  651. $them = "bach.sr.hp.com" unless $them;
  652.  
  653. $AF_INET = 2;
  654. $SOCK_STREAM = 1;
  655. $SIG{'INT'} = 'dokill';
  656. $sockaddr = 'S n a4 x8';
  657.  
  658. chop($hostname = `hostname`);
  659. ($name,$aliases,$proto) = getprotobyname('tcp');
  660. ($name,$aliases,$port) = getservbyname($port,'tcp')
  661.     unless $port =~ /^\d+$/;;
  662. ($name,$aliases,$type,$len,$thisaddr) =
  663.         gethostbyname($hostname);
  664. ($name,$aliases,$type,$len,$thataddr) = gethostbyname($them);
  665. $this = pack($sockaddr, $AF_INET, 0, $thisaddr);
  666. $that = pack($sockaddr, $AF_INET, $port, $thataddr);
  667.  
  668. if (socket(S, $AF_INET, $SOCK_STREAM, $proto)) {
  669. #    print "socket ok\n";
  670. }
  671. else {
  672.     die $!;
  673. }
  674. # Give the socket an address.
  675. if (bind(S, $this)) {
  676. #    print "bind ok\n";
  677. }
  678. else {
  679.     die $!;
  680. }
  681.  
  682. # Call up the server.
  683.  
  684. if (connect(S,$that)) {
  685. #    print "connect ok\n";
  686. }
  687. else {
  688.     die $!;
  689. }
  690.  
  691. # Set socket to be command buffered.
  692.  
  693. select(S); $| = 1; select(STDOUT);
  694.  
  695. #    print S "@PJL ECHO Hi $hostname! $ends";
  696. #    print S "@PJL OPMSG DISPLAY=\"Job $whoami\" $ends";
  697. #    print S $dpi300;
  698.  
  699. # Avoid deadlock by forking.
  700.  
  701. if($child = fork) {
  702.     print S $dosCr;
  703.     print S $TimesNewR;
  704.  
  705.     while (<IN>) {
  706.         print S;
  707.     }
  708.     sleep 3;
  709.     do dokill();
  710. } else {
  711.     while(<S>) {
  712.         print;
  713.     }
  714. }
  715.  
  716. sub dokill {
  717.     kill 9,$child if $child;
  718. }
  719. </verb></tscreen>
  720.  
  721. <sect1>Running an <em/if/ for remote printers
  722. <p>
  723. One oddity of lpd is that the <em/if/ is not run for remote printers.
  724. If you find that you need to run an <em/if/, you can do so by
  725. setting up a double queue and requeueing the job.  As an example,
  726. consider this <em/printcap/:
  727. <tscreen><verb>
  728. lj-5:remote-hplj:\
  729.         :lp=/dev/null:sh:\
  730.         :sd=/var/spool/lpd/lj-5:\
  731.     :if=/usr/lib/lpd/filter-lj-5:
  732. lj-5-remote:lp=/dev/null:sh:rm=printer.name.com:\
  733.     :rp=raw:sd=/var/spool/lpd/lj-5-raw:
  734. </verb></tscreen>
  735. in light of this <tt/filter-lj-5/ script:
  736. <tscreen><verb>
  737. #!/bin/sh
  738. gs <options> -q -dSAFER -sOutputFile=- - | \
  739.     lpr -Plj-5-remote -U$5
  740. </verb></tscreen>
  741. <p>
  742. The <em/-U/ option to lpr only works if lpr is run as daemon, and it
  743. sets the submitter's name for the job in the resubmitted queue
  744. correctly.  You should probably use a more robust method of getting
  745. the username, since in some cases it is not argument 5.  See the man
  746. page for <em><htmlurl name="printcap"
  747. url="http://www.picante.com/~gtaylor/pht/man/printcap.html"></em>.
  748.  
  749. <sect>How to print to a fax machine.
  750. <sect1>Using a faxmodem
  751. <p>
  752. There are a number of fax programs out there that will let you fax and
  753. receive documents.  One of the most complex is Sam Leffler's
  754. <em/HylaFax/, available from <tt/ftp.sgi.com/.  It supports all sorts
  755. of things from multiple modems to broadcasting.
  756. <p>
  757. Also available, and a better choice for most Linux boxen, is
  758. <tt><htmlurl name="efax"
  759. url="http://www.picante.com/~gtaylor/pht/man/efax.html"></tt>, a
  760. simple program which sends faxes.  The getty program <tt/mgetty/ can
  761. receive faxes (and even do voicemail on some modems!).
  762.  
  763. <sect1>Using the Remote Printing Service
  764. <p>
  765. There is an experimental service offered that lets you send an email
  766. message containing something you'd like printed such that it will
  767. appear on a fax machine elsewhere.  Nice formats like postscript are
  768. supported, so even though global coverage is spotty, this can still be
  769. a very useful service.  For more information on printing via the
  770. remote printing service, see the <url
  771. url="http://www.town.hall.org/fax/faq.html" name="FAQ">.
  772.  
  773.  
  774. <sect>How to generate something worth printing.
  775. <p>
  776. Here we get into a real rat's-nest of software.  Basically, Linux can
  777. run four types of binaries with varying degrees of success: Linux,
  778. iBCS, Win16/Win32s (with dosemu and, someday, with Wine), and Mac/68k
  779. (with Executor).  I'll just discuss native Linux and common Unix
  780. software, except to say that WordPerfect for SCO, and quite probably
  781. other commercial word processing software, runs fine under Linux's iBCS
  782. emulation.
  783. <p>
  784. For Linux itself, choices are mostly limited to those available for
  785. Unix in general:
  786.  
  787. <sect1>Markup languages
  788. <p>
  789. Most markup languages are more suitable for large or repetative
  790. projects, where you want the computer to control the layout of the
  791. text to make things uniform.  Trying to make a pretty sign in a markup
  792. language would probably hurt...
  793. <p>
  794. <descrip>
  795. <tag><tt>nroff</tt></tag>This was one of the first Unix markup
  796. languages.  Man pages are the most common examples of things formatted
  797. in *roff macros; many people swear by them, but nroff has, to me at
  798. least, a more arcane syntax than needed, and probably makes a poor
  799. choice for new works.  It is worth knowing, though, that you can
  800. typeset a man page directly into postscript with groff.  Most man
  801. commands will do this for you with <tt/man -t foo | lpr/.
  802.  
  803. <tag/TeX/TeX, and the macro package LaTeX, are one of the most widely
  804. used markup languages on Unix.  Technical works are frequently written
  805. in LaTeX because it greatly simplifies the layout issues and is
  806. <em/still/ one of the few text processing systems to support
  807. mathematics both completely and well.  TeX's output format is
  808. <tt/dvi/, and is converted to PostScript or Hewlett Packard's PCL with
  809. <tt/dvips/ or <tt/dvilj/.
  810.  
  811. <tag/SGML/There is at least one free sgml parser available for Unix
  812. and Linux; it forms the basis of Linuxdoc-SGML's homegrown document
  813. system.  It can support other DTD's, as well.
  814.  
  815. <tag/HTML/Someone suggested that for simple projects, it may suffice
  816. to write it in HTML and print it out using Netscape.  I disagree, but
  817. YMMV.
  818. </descrip>
  819.  
  820. <sect1>WYSIWYG
  821. <p>
  822. There is a general shortage of WYSIWYG text processing software.  Feel
  823. free to write some, and do let me know of anything I've omitted here.
  824. <descrip>
  825. <tag/Lyrix/
  826. Lyrix is a front-end to LaTeX which looks very promising.
  827. <tag/The Andrew User Interface System/
  828. AUIS includes <tt/ez/, a WYSIWYG-style editor with most basic word
  829. processor features, HTML capabilities, and full MIME email and
  830. newsgroup support.
  831. <tag/Commercial offerings/
  832. At least Caldera and Red Hat ship packages containing the
  833. usual office apps like a WYSIWYGish word processor and a spreadsheet.
  834. I would assume they do a dandy job, but I've never used them.  I
  835. think Caldera also ships Sun's WABI, so you could probably run
  836. something like MS Office under that if you had to integrate with other
  837. folks' files.
  838. <p>
  839.  
  840. Jeff Phillips <tt/<jeff@I_RATUS.org>/ uses Caldera's WordPerfect
  841. for Linux (on Slackware, of all things) and says that it works well.
  842. It apparently includes built-in printer support, as one would expect.
  843. Caldera should have info on <url url="http://www.caldera.com/">.
  844. <p>
  845.  
  846. RedHat ships a suite called <em/Applixware/; you can find their web
  847. site at <url url="http://www.redhat.com/">.
  848.  
  849. <p>
  850. Other vendors feel free to drop me a line with your offerings.
  851.  
  852. </descrip>
  853.  
  854. <sect>Ghostscript.
  855. <p>
  856. Ghostscript is an incredibly significant program for Linux printing.
  857. Most printing software under Unix generates PostScript, which is
  858. typically a $100-300 option on a printer.  Ghostscript,
  859. however, is free, and will generate the language of your printer from
  860. PostScript.  When tied in with your <tt/lpd/ input filter, it gives
  861. you a virtual PostScript printer and simplifies life immensely.
  862. <p>
  863. Ghostscript is available in two forms.  The commercial version of
  864. Ghostscript, called Aladdin Ghostscript, may be used freely for
  865. personal use but may not be distributed by commercial Linux
  866. distributions.  It is generally a year or so ahead of the free
  867. Ghostscript; at the moment, for example, it supports Adobe Acrobat's
  868. Portable Document Format, while the older Ghostscripts do not.
  869. <p>
  870. The free version of Ghostscript is GNU Ghostscript, and is simply an
  871. aged version of Aladdin ghostscript kindly given to GNU.  (Kudos to
  872. Aladdin for this arrangement; more software vendors should support
  873. free software in this way).
  874. <p>
  875. Ghostscript's main failing is in its fonts, which are derived from
  876. bitmap scans of the characters.  Superior, but commercially licensed
  877. fonts may be obtained from several places, since Ghostscript can read
  878. type 1 Adobe fonts.  Adobe distributes useable fonts with their
  879. Acrobat PDF reader, or you may use the fonts from Adobe's ATM or a
  880. fontpack.
  881. <p>
  882. Whatever you do with <tt><htmlurl name="gs"
  883. url="http://www.picante.com/~gtaylor/pht/man/gs.html"></tt>, be very
  884. sure to run it with the option for disabling file access
  885. (<tt/-dSAFER/).  PostScript is a fully functional language, and a bad
  886. PostScript program could give you quite a headache.
  887.  
  888. <sect1>Ghostscript output tuning
  889. <p>
  890. There are a number of things one can do if gs's output is not
  891. satisfactory (actually, you can do anything you darn well please,
  892. since you have the source).
  893.  
  894. <sect2>Output location and size
  895. <p>
  896. The location, size, and aspect ratio of the image on a page is
  897. controlled by the printer-specific driver in ghostscript.  If you find
  898. that your pages are coming out scrunched too short, or too long, or
  899. too big by a factor of two, you might want to look in your driver's
  900. source module and adjust whatever parameters jump out at you.
  901. Unfortunately, each driver is different, so I can't really tell you
  902. what to adjust, but most of them are reasonably well commented.
  903.  
  904. <sect2>Gamma, dotsizes, etc.
  905. <p>
  906. Most non-laser printers suffer from the fact that their dots are
  907. rather large. This results in pictures coming out too dark. If you
  908. experience this problem you should use your own transfer function.
  909. Simply create the following file in the ghostscript lib-dir and add
  910. its name to the gs call just before the actual file. You may need to
  911. tweak the actual values to fit your printer. Lower values result in a
  912. brighter print.  Especially if your driver uses a Floyd-Steinberg
  913. algorithm to rasterize colors, lower values ( 0.2 - 0.15 ) are
  914. probably a good choice.
  915.  
  916. <tscreen><verb>
  917. ---8<---- gamma.ps ----8<---
  918. %!
  919. %transfer functions for cyan magenta yellow black
  920. {0.3 exp} {0.3 exp} {0.3 exp} {0.3 exp} setcolortransfer
  921. ---8<------------------8<---
  922. </verb></tscreen>
  923.  
  924. <p>
  925. It is also possible to mend printers that have some kind of colour
  926. fault by tweaking these values. If you do that kind of thing, I
  927. recommend using the file colorcir.ps, that comes with ghostscript (in
  928. the examples/ subdir), as a test page.
  929.  
  930.  
  931. <sect>On-screen previewing of printable things.
  932. <p>
  933. Nearly anything you can print can be viewed on the screen, too.
  934. <sect1>PostScript
  935. <p>
  936. Ghostscript has an X11 driver best used under the management of the
  937. PostScript previewer <htmlurl name="Ghostview"
  938. url="http://www.picante.com/~gtaylor/pht/man/ghostview.html">.  The
  939. latest versions of these programs should be able to view PDF files, as
  940. well.  
  941.  
  942. <sect1>TeX dvi
  943. <p>
  944. TeX DeVice Independant files may be previewed under X11 with <htmlurl
  945. name="xdvi" url="http://www.picante.com/~gtaylor/pht/man/xdvi.html">.
  946. Modern versions of xdvi call ghostscript to render PostScript
  947. specials.
  948. <p>
  949. A VT100 driver exists as well.  It's called <tt/dgvt/.  <tt/Tmview/
  950. works with Linux and svgalib, if that's all you can do.
  951.  
  952. <sect>Credits
  953. <p>
  954. The <tt/smbprint/ information is from an article by Marcel Roelofs
  955. <tt/<marcel@paragon.nl>/.
  956.  
  957. <p>
  958. The <tt/nprint/ information for using Netware printers was provided by
  959. Michael Smith <tt/<mikes@bioch.ox.ac.uk>/.
  960.  
  961. <p>
  962. The serial printers under lpd section is from Andrew Tefft
  963. <tt/<teffta@engr.dnet.ge.com>/.
  964.  
  965. <p>
  966. The blurb about gammas and such for gs was sent in by Andreas
  967. <tt/<quasi@hub-fue.franken.de>/.
  968.  
  969. </article>
  970.