?? printing-intro-setup.html
字號:
<p>This section tells you how to check if FreeBSD can communicate with a printer on aserial port.</p><p><span class="emphasis"><i class="EMPHASIS">To test a printer on a serialport:</i></span></p><div class="PROCEDURE"><ol type="1"><li><p>Become <tt class="USERNAME">root</tt> with <span class="CITEREFENTRY"><spanclass="REFENTRYTITLE">su</span>(1)</span>.</p></li><li><p>Edit the file <tt class="FILENAME">/etc/remote</tt>. Add the following entry:</p><pre class="PROGRAMLISTING">printer:dv=/dev/<var class="REPLACEABLE">port</var>:br#<varclass="REPLACEABLE">bps-rate</var>:pa=<var class="REPLACEABLE">parity</var></pre><p>Where <var class="REPLACEABLE">port</var> is the device entry for the serial port(<var class="LITERAL">ttyd0</var>, <var class="LITERAL">ttyd1</var>, etc.), <varclass="REPLACEABLE">bps-rate</var> is the bits-per-second rate at which the printercommunicates, and <var class="REPLACEABLE">parity</var> is the parity required by theprinter (either <var class="LITERAL">even</var>, <var class="LITERAL">odd</var>, <varclass="LITERAL">none</var>, or <var class="LITERAL">zero</var>).</p><p>Here is a sample entry for a printer connected via a serial line to the third serialport at 19200 bps with no parity:</p><pre class="PROGRAMLISTING">printer:dv=/dev/ttyd2:br#19200:pa=none</pre></li><li><p>Connect to the printer with <span class="CITEREFENTRY"><spanclass="REFENTRYTITLE">tip</span>(1)</span>. Type:</p><pre class="SCREEN"><samp class="PROMPT">#</samp> <kbd class="USERINPUT">tip printer</kbd></pre><p>If this step does not work, edit the file <tt class="FILENAME">/etc/remote</tt> againand try using <tt class="FILENAME">/dev/cuaa<var class="REPLACEABLE">N</var></tt> insteadof <tt class="FILENAME">/dev/ttyd<var class="REPLACEABLE">N</var></tt>.</p></li><li><p>Send data to the printer.</p><ul><li><p>If the printer can print plain text, then use <span class="CITEREFENTRY"><spanclass="REFENTRYTITLE">lptest</span>(1)</span>. Type:</p><pre class="SCREEN"><samp class="PROMPT">%</samp> <kbd class="USERINPUT">$lptest</kbd></pre></li><li><p>If the printer understands <span class="TRADEMARK">PostScript</span> or other printerlanguage, then send a small program to the printer. Type the program, line by line, <spanclass="emphasis"><i class="EMPHASIS">very carefully</i></span> as backspacing or otherediting keys may be significant to the printer. You may also need to type a specialend-of-file key for the printer so it knows it received the whole program. For <spanclass="TRADEMARK">PostScript</span> printers, press <varclass="LITERAL">CONTROL+D</var>.</p><p>Alternatively, you can put the program in a file and type:</p><pre class="SCREEN"><samp class="PROMPT">%</samp> <kbd class="USERINPUT">><varclass="REPLACEABLE">file</var></kbd></pre><p>Where <var class="REPLACEABLE">file</var> is the name of the file containing theprogram. After <span class="CITEREFENTRY"><spanclass="REFENTRYTITLE">tip</span>(1)</span> sends the file, press any required end-of-filekey.</p></li></ul></li></ol></div><p>You should see something print. Do not worry if the text does not look right; we willfix that later.</p></div></div></div><div class="SECT3"><h3 class="SECT3"><a id="PRINTING-PRINTCAP" name="PRINTING-PRINTCAP">9.3.1.4. Enablingthe Spooler: the <tt class="FILENAME">/etc/printcap</tt> File</a></h3><p>At this point, your printer should be hooked up, your kernel configured to communicatewith it (if necessary), and you have been able to send some simple data to the printer.Now, we are ready to configure <b class="APPLICATION">LPD</b> to control access to yourprinter.</p><p>You configure <b class="APPLICATION">LPD</b> by editing the file <ttclass="FILENAME">/etc/printcap</tt>. The <b class="APPLICATION">LPD</b> spooling systemreads this file each time the spooler is used, so updates to the file take immediateeffect.</p><p>The format of the <span class="CITEREFENTRY"><spanclass="REFENTRYTITLE">printcap</span>(5)</span> file is straightforward. Use yourfavorite text editor to make changes to <tt class="FILENAME">/etc/printcap</tt>. Theformat is identical to other capability files like <ttclass="FILENAME">/usr/share/misc/termcap</tt> and <tt class="FILENAME">/etc/remote</tt>.For complete information about the format, see the <span class="CITEREFENTRY"><spanclass="REFENTRYTITLE">cgetent</span>(3)</span>.</p><p>The simple spooler configuration consists of the following steps:</p><div class="PROCEDURE"><ol type="1"><li><p>Pick a name (and a few convenient aliases) for the printer, and put them in the <ttclass="FILENAME">/etc/printcap</tt> file; see the <ahref="printing-intro-setup.html#PRINTING-NAMING">Naming the Printer</a> section for moreinformation on naming.</p></li><li><p>Turn off header pages (which are on by default) by inserting the <varclass="LITERAL">sh</var> capability; see the <ahref="printing-intro-setup.html#PRINTING-NO-HEADER-PAGES">Suppressing Header Pages</a>section for more information.</p></li><li><p>Make a spooling directory, and specify its location with the <varclass="LITERAL">sd</var> capability; see the <ahref="printing-intro-setup.html#PRINTING-SPOOLDIR">Making the Spooling Directory</a>section for more information.</p></li><li><p>Set the <tt class="FILENAME">/dev</tt> entry to use for the printer, and note it in<tt class="FILENAME">/etc/printcap</tt> with the <var class="LITERAL">lp</var>capability; see the <a href="printing-intro-setup.html#PRINTING-DEVICE">Identifying thePrinter Device</a> for more information. Also, if the printer is on a serial port, set upthe communication parameters with the <var class="LITERAL">ms#</var> capability which isdiscussed in the <a href="printing-intro-setup.html#PRINTING-COMMPARAM">ConfiguringSpooler Communications Parameters</a> section.</p></li><li><p>Install a plain text input filter; see the <ahref="printing-intro-setup.html#PRINTING-TEXTFILTER">Installing the Text Filter</a>section for details.</p></li><li><p>Test the setup by printing something with the <span class="CITEREFENTRY"><spanclass="REFENTRYTITLE">lpr</span>(1)</span> command. More details are available in the <ahref="printing-intro-setup.html#PRINTING-TRYING">Trying It Out</a> and <ahref="printing-troubleshooting.html">Troubleshooting</a> sections.</p></li></ol></div><div class="NOTE"><blockquote class="NOTE"><p><b>注:</b> Language-based printers, such as <span class="TRADEMARK">PostScript</span>printers, cannot directly print plain text. The simple setup outlined above and describedin the following sections assumes that if you are installing such a printer you willprint only files that the printer can understand.</p></blockquote></div><p>Users often expect that they can print plain text to any of the printers installed onyour system. Programs that interface to <b class="APPLICATION">LPD</b> to do theirprinting usually make the same assumption. If you are installing such a printer and wantto be able to print jobs in the printer language <span class="emphasis"><iclass="EMPHASIS">and</i></span> print plain text jobs, you are strongly urged to add anadditional step to the simple setup outlined above: install an automaticplain-text-to-<span class="TRADEMARK">PostScript</span> (or other printer language)conversion program. The section entitled <ahref="printing-advanced.html#PRINTING-ADVANCED-IF-CONVERSION">Accommodating Plain TextJobs on <span class="TRADEMARK">PostScript</span> Printers</a> tells how to do this.</p><div class="SECT4"><h4 class="SECT4"><a id="PRINTING-NAMING" name="PRINTING-NAMING">9.3.1.4.1. Naming thePrinter</a></h4><p>The first (easy) step is to pick a name for your printer It really does not matterwhether you choose functional or whimsical names since you can also provide a number ofaliases for the printer.</p><p>At least one of the printers specified in the <tt class="FILENAME">/etc/printcap</tt>should have the alias <var class="LITERAL">lp</var>. This is the default printer's name.If users do not have the <tt class="ENVAR">PRINTER</tt> environment variable nor specifya printer name on the command line of any of the <b class="APPLICATION">LPD</b> commands,then <var class="LITERAL">lp</var> will be the default printer they get to use.</p><p>Also, it is common practice to make the last alias for a printer be a full descriptionof the printer, including make and model.</p><p>Once you have picked a name and some common aliases, put them in the <ttclass="FILENAME">/etc/printcap</tt> file. The name of the printer should start in theleftmost column. Separate each alias with a vertical bar and put a colon after the lastalias.</p><p>In the following example, we start with a skeletal <ttclass="FILENAME">/etc/printcap</tt> that defines two printers (a Diablo 630 line printerand a Panasonic KX-P4455 <span class="TRADEMARK">PostScript</span> laser printer):</p><pre class="PROGRAMLISTING">## /etc/printcap for host rose#rattan|line|diablo|lp|Diablo 630 Line Printer:bamboo|ps|PS|S|panasonic|Panasonic KX-P4455 PostScript v51.4:</pre><p>In this example, the first printer is named <var class="LITERAL">rattan</var> and hasas aliases <var class="LITERAL">line</var>, <var class="LITERAL">diablo</var>, <varclass="LITERAL">lp</var>, and <var class="LITERAL">Diablo 630 Line Printer</var>. Sinceit has the alias <var class="LITERAL">lp</var>, it is also the default printer. Thesecond is named <var class="LITERAL">bamboo</var>, and has as aliases <varclass="LITERAL">ps</var>, <var class="LITERAL">PS</var>, <var class="LITERAL">S</var>,<var class="LITERAL">panasonic</var>, and <var class="LITERAL">Panasonic KX-P4455PostScript v51.4</var>.</p></div><div class="SECT4"><h4 class="SECT4"><a id="PRINTING-NO-HEADER-PAGES"name="PRINTING-NO-HEADER-PAGES">9.3.1.4.2. Suppressing Header Pages</a></h4><p>The <b class="APPLICATION">LPD</b> spooling system will by default print a <spanclass="emphasis"><i class="EMPHASIS">header page</i></span> for each job. The header pagecontains the user name who requested the job, the host from which the job came, and thename of the job, in nice large letters. Unfortunately, all this extra text gets in theway of debugging the simple printer setup, so we will suppress header pages.</p><p>To suppress header pages, add the <var class="LITERAL">sh</var> capability to theentry for the printer in <tt class="FILENAME">/etc/printcap</tt>. Here is an example <ttclass="FILENAME">/etc/printcap</tt> with <var class="LITERAL">sh</var> added:</p><pre class="PROGRAMLISTING">## /etc/printcap for host rose - no header pages anywhere#rattan|line|diablo|lp|Diablo 630 Line Printer:\ :sh:bamboo|ps|PS|S|panasonic|Panasonic KX-P4455 PostScript v51.4:\ :sh:</pre><p>Note how we used the correct format: the first line starts in the leftmost column, andsubsequent lines are indented with a single TAB. Every line in an entry except the lastends in a backslash character.</p></div><div class="SECT4"><h4 class="SECT4"><a id="PRINTING-SPOOLDIR" name="PRINTING-SPOOLDIR">9.3.1.4.3. Makingthe Spooling Directory</a></h4><p>The next step in the simple spooler setup is to make a <span class="emphasis"><iclass="EMPHASIS">spooling directory</i></span>, a directory where print jobs reside untilthey are printed, and where a number of other spooler support files live.</p><p>Because of the variable nature of spooling directories, it is customary to put thesedirectories under <tt class="FILENAME">/var/spool</tt>. It is not necessary to backup thecontents of spooling directories, either. Recreating them is as simple as running <spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">mkdir</span>(1)</span>.</p><p>It is also customary to make the directory with a name that is identical to the nameof the printer, as shown below:</p><pre class="SCREEN"><samp class="PROMPT">#</samp> <kbd class="USERINPUT">mkdir /var/spool/<varclass="REPLACEABLE">printer-name</var></kbd></pre><p>However, if you have a lot of printers on your network, you might want to put thespooling directories under a single directory that you reserve just for printing with <bclass="APPLICATION">LPD</b>. We will do this for our two example printers <varclass="LITERAL">rattan</var> and <var class="LITERAL">bamboo</var>:</p><pre class="SCREEN"><samp class="PROMPT">#</samp> <kbd class="USERINPUT">mkdir /var/spool/lpd</kbd><samp class="PROMPT">#</samp> <kbd class="USERINPUT">mkdir /var/spool/lpd/rattan</kbd><samp class="PROMPT">#</samp> <kbd class="USERINPUT">mkdir /var/spool/lpd/bamboo</kbd></pre><div class="NOTE"><blockquote class="NOTE"><p><b>注:</b> If you are concerned about the privacy of jobs that users print, you mightwant to protect the spooling directory so it is not publicly accessible. Spoolingdirectories should be owned and be readable, writable, and searchable by user daemon andgroup daemon, and no one else. We will do this for our example printers:</p><pre class="SCREEN"><samp class="PROMPT">#</samp> <kbdclass="USERINPUT">chown daemon:daemon /var/spool/lpd/rattan</kbd><samp class="PROMPT">#</samp> <kbdclass="USERINPUT">chown daemon:daemon /var/spool/lpd/bamboo</kbd><samp class="PROMPT">#</samp> <kbdclass="USERINPUT">chmod 770 /var/spool/lpd/rattan</kbd><samp class="PROMPT">#</samp> <kbdclass="USERINPUT">chmod 770 /var/spool/lpd/bamboo</kbd></pre></blockquote></div><p>Finally, you need to tell <b class="APPLICATION">LPD</b> about these directories usingthe <tt class="FILENAME">/etc/printcap</tt> file. You specify the pathname of the
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -