<!--#include virtual="HTML_begin.inc"-->
  <title>LPR Printing on Linux</title>
  <meta name="keywords" content="Computer, Linux, FreeBSD"/>
  <meta name="keywords" content="lpr, printing, dot matrix, ascii, printcap, \
    groff, man page, pr"/>
<!--#include virtual="HTML_head_end.inc"-->
<!--#include virtual="Computer_tabs.inc"-->

<div id="content">
<h2>Information on LPR Printing</h2>

<p>Basic printing service setup is beyond the scope of this document. The
printing howto's do a good job of explaining the lpr printing system. This
document is designed to provide additional information about some of the more
mundane requirements a person might have. Like:</p>

<h3>Reviving an old Dot Matrix printer</h3>

<h4>Resources:</h4>

<ul>
  <li>man pages or info pages:
    <p><tt>lpr(1), lpq(1), lprm(1), lpc(8), lpd(8), printcap(5), pr(1),
    tunelp(8), enscript(1), a2ps(1)</tt></p>
  </li>
  <li>HOW-TOs:
    <p><tt>Printing-HOWTO</tt></p>
  </li>
</ul>

<h4>Printing ASCII text to a dot matrix printer</h4>

<p>Printing to a character based printer is a simple task; however, some people
may have little knowledge of these ancient beasts. After inheriting a couple of
boxes of form feed paper and recovering my 16 year old FX-80 from the closet I
configured an old DEC Multia as a print server for the Epson. It is great for
printing huge README files, HOWTO files, etc.. The paper is cheap; the printer
ribbon is cheap; the time is cheap; and the Multia and Epson could care less
about the hours of cranking out documentation.  In character mode these old
printers are reasonably fast&mdash;fast enough to do source code listings and
draft quality printouts of your latest article.  Unfortunately, they are
extremely slow in graphics mode.</p>

<ol>
  <li>/etc/printcap

  <p>The following is a fairly typical entry in <tt>/etc/printcap</tt>
  for an Epson FX-80 printing ASCII text:</p>

  <pre>
    text|fx80text:\
        :lp=/dev/lp0:\
        :sd=/var/spool/lpd/fx80:\
        :lf=/var/spool/lpd/fx80/errs:\
        :if=/var/spool/lpd/fx80/FX80Filter:\
        :mx#0:\
        :sh:\</pre>
  </li>
  <li>Spool directory and filter

  <p>Create the spool directory <tt>/var/spool/lpd/fx80</tt> and put the filter
  named <tt>FX80Filter</tt>(see below) in it.  The line in
  <tt>/etc/printcap</tt> beginning "<tt>:if=</tt>" tells lpd where the input
  filter is located.</p>

  <p>A very simple filter that does nothing but forward the text to the printer
  would look like this:</p>

  <pre>
    #!/bin/sh
    cat</pre>

  <p>Filters to send ASCII text to a dot matrix printer can take advantage of
  some of the printer's built-in features: choice of fonts, emphasized mode,
  skip-over-perforations, etc.. The following filter demonstrates some basic
  controls for an Epson FX-80 printer.</p>

  <pre>
    #!/bin/bash
    RESET=\\033@
    ELITE=\\033M
    LEFTMARGIN=\\033l\\007
    SOP=\\033N\\006
    FF=\\014
    echo -ne $RESET$ELITE$LEFTMARGIN$SOP
    cat
    echo -ne $FF</pre>

  <p>The first line explicitely calls <tt>bash</tt> instead of <tt>sh</tt>
  because "<tt>echo -ne</tt>" is specific to <tt>bash</tt>.  Escaped octal is
  used because hex does not seem to work when sent to the printer; however, hex
  works when sent to the console. The filter will reset the printer, change it
  to elite mode, set a left margin (for punching holes to install paper into a
  ring binder), and skip-over-perforations, then print text sent from lpr, and,
  finally, form-feed the last page. Setting the font to elite allows a total of
  96 characters to be printed on one line. In this example the left margin is 6
  so you can still print a line of 90 characters.</p>

  <p>Instead of using a filter to format the text for the printer you can use
  <tt>pr</tt>. The filter can then be simplified.  The example below uses the
  filter to set the printer to elite mode and leaves it up to <tt>pr</tt> to
  set a left margin or other niceties.</p>

  <pre>
    #!/bin/bash
    RESET=\\033@
    ELITE=\\033M
    FF=\\014
    echo -ne $RESET$ELITE
    cat
    echo -ne $FF</pre>
  </li>

  <li>Printing ASCII to printer

    <ul>
      <li>Text file to printer:
        <p><tt>lpr -Ptext any-ascii-text.txt</tt></p>
      </li>
      <li>Troff to ASCII to printer:
        <p><tt>groff -Tascii finename.tr | lpr</tt></p>
      </li>
      <li>Man pages to ASCII to printer (man pages are
          pre-formatted troff):
        <p><tt>man man | col -b | lpr</tt></p>
      </li>
      <li>Using pr to format ASCII text to printer:
        <p><tt>pr filename.txt | lpr</tt></p>
      </li>
    </ul>

  </li>
</ol>

</div>

<p class="lastupdate">Last updated: <!--#echo var="LAST_MODIFIED" --></p>
<!--#include virtual="HTML_end.inc"-->
