⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 printing-advanced.html

📁 FreeBSD操作系统的详细使用手册
💻 HTML
📖 第 1 页 / 共 5 页
字号:
<p>However, an output filter is <span class="emphasis"><iclass="EMPHASIS">necessary</i></span> if you want header pages and need to send escapesequences or other initialization strings to be able to print the header page. (But it isalso <span class="emphasis"><i class="EMPHASIS">futile</i></span> if you want to chargeheader pages to the requesting user's account, since <b class="APPLICATION">LPD</b> doesnot give any user or host information to the output filter.)</p><p>On a single printer, <b class="APPLICATION">LPD</b> allows both an output filter andtext or other filters. In such cases, <b class="APPLICATION">LPD</b> will start theoutput filter to print the header page (see section <ahref="printing-advanced.html#PRINTING-ADVANCED-HEADER-PAGES">Header Pages</a>) only. <bclass="APPLICATION">LPD</b> then expects the output filter to <span class="emphasis"><iclass="EMPHASIS">stop itself</i></span> by sending two bytes to the filter: ASCII 031followed by ASCII 001. When an output filter sees these two bytes (031, 001), it shouldstop by sending <var class="LITERAL">SIGSTOP</var> to itself. When <bclass="APPLICATION">LPD</b>'s done running other filters, it will restart the outputfilter by sending <var class="LITERAL">SIGCONT</var> to it.</p><p>If there is an output filter but <span class="emphasis"><iclass="EMPHASIS">no</i></span> text filter and <b class="APPLICATION">LPD</b> is workingon a plain text job, <b class="APPLICATION">LPD</b> uses the output filter to do the job.As stated before, the output filter will print each file of the job in sequence with nointervening form feeds or other paper advancement, and this is probably <spanclass="emphasis"><i class="EMPHASIS">not</i></span> what you want. In almost all cases,you need a text filter.</p><p>The program <tt class="COMMAND">lpf</tt>, which we introduced earlier as a textfilter, can also run as an output filter. If you need a quick-and-dirty output filter butdo not want to write the byte detection and signal sending code, try <ttclass="COMMAND">lpf</tt>. You can also wrap <tt class="COMMAND">lpf</tt> in a shellscript to handle any initialization codes the printer might require.</p></div><div class="SECT3"><h3 class="SECT3"><a id="PRINTING-ADVANCED-LPF" name="PRINTING-ADVANCED-LPF">9.4.1.6 <ttclass="COMMAND">lpf</tt>: a Text Filter</a></h3><p>The program <tt class="FILENAME">/usr/libexec/lpr/lpf</tt> that comes with FreeBSDbinary distribution is a text filter (input filter) that can indent output (job submittedwith <tt class="COMMAND">lpr -i</tt>), allow literal characters to pass (job submittedwith <tt class="COMMAND">lpr -l</tt>), adjust the printing position for backspaces andtabs in the job, and account for pages printed. It can also act like an outputfilter.</p><p><tt class="COMMAND">lpf</tt> is suitable for many printing environments. And althoughit has no capability to send initialization sequences to a printer, it is easy to write ashell script to do the needed initialization and then execute <ttclass="COMMAND">lpf</tt>.</p><p>In order for <tt class="COMMAND">lpf</tt> to do page accounting correctly, it needscorrect values filled in for the <var class="LITERAL">pw</var> and <varclass="LITERAL">pl</var> capabilities in the <tt class="FILENAME">/etc/printcap</tt>file. It uses these values to determine how much text can fit on a page and how manypages were in a user's job. For more information on printer accounting, see <ahref="printing-advanced.html#PRINTING-ADVANCED-ACCT">Accounting for PrinterUsage</a>.</p></div></div><div class="SECT2"><h2 class="SECT2"><a id="PRINTING-ADVANCED-HEADER-PAGES"name="PRINTING-ADVANCED-HEADER-PAGES">9.4.2 Header Pages</a></h2><p>If you have <span class="emphasis"><i class="EMPHASIS">lots</i></span> of users, allof them using various printers, then you probably want to consider <spanclass="emphasis"><i class="EMPHASIS">header pages</i></span> as a necessary evil.</p><p>Header pages, also known as <span class="emphasis"><iclass="EMPHASIS">banner</i></span> or <span class="emphasis"><i class="EMPHASIS">burstpages</i></span> identify to whom jobs belong after they are printed. They are usuallyprinted in large, bold letters, perhaps with decorative borders, so that in a stack ofprintouts they stand out from the real documents that comprise users' jobs. They enableusers to locate their jobs quickly. The obvious drawback to a header page is that it isyet one more sheet that has to be printed for every job, their ephemeral usefulnesslasting not more than a few minutes, ultimately finding themselves in a recycling bin orrubbish heap. (Note that header pages go with each job, not each file in a job, so thepaper waste might not be that bad.)</p><p>The <b class="APPLICATION">LPD</b> system can provide header pages automatically foryour printouts <span class="emphasis"><i class="EMPHASIS">if</i></span> your printer candirectly print plain text. If you have a <span class="TRADEMARK">PostScript</span>printer, you will need an external program to generate the header page; see <ahref="printing-advanced.html#PRINTING-ADVANCED-HEADER-PAGES-PS">Header Pages on <spanclass="TRADEMARK">PostScript</span> Printers</a>.</p><div class="SECT3"><h3 class="SECT3"><a id="PRINTING-ADVANCED-HEADER-PAGES-ENABLING"name="PRINTING-ADVANCED-HEADER-PAGES-ENABLING">9.4.2.1 Enabling Header Pages</a></h3><p>In the <a href="printing-intro-setup.html#PRINTING-SIMPLE">Simple Printer Setup</a>section, we turned off header pages by specifying <var class="LITERAL">sh</var> (meaning``suppress header'') in the <tt class="FILENAME">/etc/printcap</tt> file. To enableheader pages for a printer, just remove the <var class="LITERAL">sh</var> capability.</p><p>Sounds too easy, right?</p><p>You are right. You <span class="emphasis"><i class="EMPHASIS">might</i></span> have toprovide an output filter to send initialization strings to the printer. Here is anexample output filter for Hewlett Packard PCL-compatible printers:</p><pre class="PROGRAMLISTING">#!/bin/sh##  hpof - Output filter for Hewlett Packard PCL-compatible printers#  Installed in /usr/local/libexec/hpofprintf "\033&amp;k2G" || exit 2exec /usr/libexec/lpr/lpf</pre><p>Specify the path to the output filter in the <var class="LITERAL">of</var> capability.See the <a href="printing-advanced.html#PRINTING-ADVANCED-OF">Output Filters</a> sectionfor more information.</p><p>Here is an example <tt class="FILENAME">/etc/printcap</tt> file for the printer <varclass="LITERAL">teak</var> that we introduced earlier; we enabled header pages and addedthe above output filter:</p><pre class="PROGRAMLISTING">##  /etc/printcap for host orchid#teak|hp|laserjet|Hewlett Packard LaserJet 3Si:\        :lp=/dev/lpt0:sd=/var/spool/lpd/teak:mx#0:\        :if=/usr/local/libexec/hpif:\        :vf=/usr/local/libexec/hpvf:\        :of=/usr/local/libexec/hpof:</pre><p>Now, when users print jobs to <var class="LITERAL">teak</var>, they get a header pagewith each job. If users want to spend time searching for their printouts, they cansuppress header pages by submitting the job with <tt class="COMMAND">lpr -h</tt>; see the<a href="printing-using.html#PRINTING-LPR-OPTIONS-MISC">Header Page Options</a> sectionfor more <a href="http://www.FreeBSD.org/cgi/man.cgi?query=lpr&sektion=1"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">lpr</span>(1)</span></a> options.</p><div class="NOTE"><blockquote class="NOTE"><p><b>Note:</b> <b class="APPLICATION">LPD</b> prints a form feed character after theheader page. If your printer uses a different character or sequence of characters toeject a page, specify them with the <var class="LITERAL">ff</var> capability in <ttclass="FILENAME">/etc/printcap</tt>.</p></blockquote></div></div><div class="SECT3"><h3 class="SECT3"><a id="PRINTING-ADVANCED-HEADER-PAGES-CONTROLLING"name="PRINTING-ADVANCED-HEADER-PAGES-CONTROLLING">9.4.2.2 Controlling HeaderPages</a></h3><p>By enabling header pages, <b class="APPLICATION">LPD</b> will produce a <spanclass="emphasis"><i class="EMPHASIS">long header</i></span>, a full page of large lettersidentifying the user, host, and job. Here is an example (kelly printed the job namedoutline from host <tt class="HOSTID">rose</tt>):</p><pre class="PROGRAMLISTING">      k                   ll       ll      k                    l        l      k                    l        l      k   k     eeee       l        l     y    y      k  k     e    e      l        l     y    y      k k      eeeeee      l        l     y    y      kk k     e           l        l     y    y      k   k    e    e      l        l     y   yy      k    k    eeee      lll      lll     yyy y                                               y                                          y    y                                           yyyy                                   ll                          t         l        i                          t         l       oooo    u    u   ttttt       l       ii     n nnn     eeee      o    o   u    u     t         l        i     nn   n   e    e      o    o   u    u     t         l        i     n    n   eeeeee      o    o   u    u     t         l        i     n    n   e      o    o   u   uu     t  t      l        i     n    n   e    e       oooo     uuu u      tt      lll      iii    n    n    eeee      r rrr     oooo     ssss     eeee      rr   r   o    o   s    s   e    e      r        o    o    ss      eeeeee      r        o    o      ss    e      r        o    o   s    s   e    e      r         oooo     ssss     eeee                                              Job:  outline                                              Date: Sun Sep 17 11:04:58 1995</pre><p><b class="APPLICATION">LPD</b> appends a form feed after this text so the job startson a new page (unless you have <var class="LITERAL">sf</var> (suppress form feeds) in thedestination printer's entry in <tt class="FILENAME">/etc/printcap</tt>).</p><p>If you prefer, <b class="APPLICATION">LPD</b> can make a <span class="emphasis"><iclass="EMPHASIS">short header</i></span>; specify <var class="LITERAL">sb</var> (shortbanner) in the <tt class="FILENAME">/etc/printcap</tt> file. The header page will looklike this:</p><pre class="PROGRAMLISTING">rose:kelly  Job: outline  Date: Sun Sep 17 11:07:51 1995</pre><p>Also by default, <b class="APPLICATION">LPD</b> prints the header page first, then thejob. To reverse that, specify <var class="LITERAL">hl</var> (header last) in <ttclass="FILENAME">/etc/printcap</tt>.</p></div><div class="SECT3"><h3 class="SECT3"><a id="PRINTING-ADVANCED-HEADER-PAGES-ACCOUNTING"name="PRINTING-ADVANCED-HEADER-PAGES-ACCOUNTING">9.4.2.3 Accounting for HeaderPages</a></h3><p>Using <b class="APPLICATION">LPD</b>'s built-in header pages enforces a particularparadigm when it comes to printer accounting: header pages must be <spanclass="emphasis"><i class="EMPHASIS">free of charge</i></span>.</p><p>Why?</p><p>Because the output filter is the only external program that will have control when theheader page is printed that could do accounting, and it is not provided with any <spanclass="emphasis"><i class="EMPHASIS">user or host</i></span> information or an accountingfile, so it has no idea whom to charge for printer use. It is also not enough to just``add one page'' to the text filter or any of the conversion filters (which do have userand host information) since users can suppress header pages with <tt class="COMMAND">lpr-h</tt>. They could still be charged for header pages they did not print. Basically, <ttclass="COMMAND">lpr -h</tt> will be the preferred option of environmentally-minded users,but you cannot offer any incentive to use it.</p><p>It is <span class="emphasis"><i class="EMPHASIS">still not enough</i></span> to haveeach of the filters generate their own header pages (thereby being able to charge forthem). If users wanted the option of suppressing the header pages with <ttclass="COMMAND">lpr -h</tt>, they will still get them and be charged for them since <bclass="APPLICATION">LPD</b> does not pass any knowledge of the <varclass="OPTION">-h</var> option to any of the filters.</p><p>So, what are your options?</p><p>You can:</p><ul><li><p>Accept <b class="APPLICATION">LPD</b>'s paradigm and make header pages free.</p></li><li><p>Install an alternative to <b class="APPLICATION">LPD</b>, such as <bclass="APPLICATION">LPRng</b>. Section <ahref="printing-lpd-alternatives.html">Alternatives to the Standard Spooler</a> tells moreabout other spooling software you can substitute for <b class="APPLICATION">LPD</b>.</p></li><li><p>Write a <span class="emphasis"><i class="EMPHASIS">smart</i></span> output filter.Normally, an output filter is not meant to do anything more than initialize a printer ordo some simple character conversion. It is suited for header pages and plain text jobs(when there is no text (input) filter). But, if there is a text filter for the plain textjobs, then <b class="APPLICATION">LPD</b> will start the output filter only for theheader pages. And the output filter can parse the header page text that <bclass="APPLICATION">LPD</b> generates to determine what user and host to charge for theheader page. The only other problem with this method is that the output filter still doesnot know what accounting file to use (it is not passed the name of the file from the <varclass="LITERAL">af</var> capability), but if you have a well-known accounting file, youcan hard-code that into the output filter. To facilitate the parsing step, use the <varclass="LITERAL">sh</var> (short header) capability in <ttclass="FILENAME">/etc/printcap</tt>. Then again, all that might be too much trouble, andusers will certainly appreciate the more generous system administrator who makes headerpages free.</p></li></ul></div><div class="SECT3"><h3 class="SECT3"><a id="PRINTING-ADVANCED-HEADER-PAGES-PS"name="PRINTING-ADVANCED-HEADER-PAGES-PS">9.4.2.4 Header Pages on <spanclass="TRADEMARK">PostScript</span> Printers</a></h3><p>As described above, <b class="APPLICATION">LPD</b> can generate a plain text headerpage suitable for many printers. Of course, <span class="TRADEMARK">PostScript</span>cannot directly print plain text, so the header page feature of <bclass="APPLICATION">LPD</b> is useless--or mostly so.</p><p>One obvious way to get header pages is to have every conversion filter and the textfilter generate the header page. The filters should use the user and host arguments togenerate a suitable header page. The drawback of this method is that users will alwaysget a header page, even if they submit jobs with <tt class="COMMAND">lpr -h</tt>.</p><p>Let us explore this method. The following script takes three arguments (user loginname, host name, and job name) and makes a simple <spanclass="TRADEMARK">PostScript</span> header page:</p><pre class="PROGRAMLISTING">#!/bin/sh##  make-ps-header - make a PostScript header page on stdout#  Installed in /usr/local/libexec/make-ps-header##

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -