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

📄 printing-advanced.html

📁 FreeBSD操作系统的详细使用手册
💻 HTML
📖 第 1 页 / 共 5 页
字号:
name="PRINTING-ADVANCED-IF-CONVERSION">9.4.1.2 Accommodating Plain Text Jobs on <spanclass="TRADEMARK">PostScript</span>&reg; Printers</a></h3><p>If you are the only user of your computer and <spanclass="TRADEMARK">PostScript</span> (or other language-based) printer, and you promise tonever send plain text to your printer and to never use features of various programs thatwill want to send plain text to your printer, then you do not need to worry about thissection at all.</p><p>But, if you would like to send both <span class="TRADEMARK">PostScript</span> andplain text jobs to the printer, then you are urged to augment your printer setup. To doso, we have the text filter detect if the arriving job is plain text or <spanclass="TRADEMARK">PostScript</span>. All <span class="TRADEMARK">PostScript</span> jobsmust start with <var class="LITERAL">%!</var> (for other printer languages, see yourprinter documentation). If those are the first two characters in the job, we have <spanclass="TRADEMARK">PostScript</span>, and can pass the rest of the job directly. If thoseare not the first two characters in the file, then the filter will convert the text into<span class="TRADEMARK">PostScript</span> and print the result.</p><p>How do we do this?</p><p>If you have got a serial printer, a great way to do it is to install <ttclass="COMMAND">lprps</tt>. <tt class="COMMAND">lprps</tt> is a <spanclass="TRADEMARK">PostScript</span> printer filter which performs two-way communicationwith the printer. It updates the printer's status file with verbose information from theprinter, so users and administrators can see exactly what the state of the printer is(such as ``<tt class="ERRORNAME">toner low</tt>'' or ``<tt class="ERRORNAME">paperjam</tt>''). But more importantly, it includes a program called <ttclass="COMMAND">psif</tt> which detects whether the incoming job is plain text and calls<tt class="COMMAND">textps</tt> (another program that comes with <ttclass="COMMAND">lprps</tt>) to convert it to <span class="TRADEMARK">PostScript</span>.It then uses <tt class="COMMAND">lprps</tt> to send the job to the printer.</p><p><tt class="COMMAND">lprps</tt> is part of the FreeBSD Ports Collection (see <ahref="ports.html">The Ports Collection</a>). You can fetch, build and install ityourself, of course. After installing <tt class="COMMAND">lprps</tt>, just specify thepathname to the <tt class="COMMAND">psif</tt> program that is part of <ttclass="COMMAND">lprps</tt>. If you installed <tt class="COMMAND">lprps</tt> from theports collection, use the following in the serial <spanclass="TRADEMARK">PostScript</span> printer's entry in <ttclass="FILENAME">/etc/printcap</tt>:</p><pre class="PROGRAMLISTING">:if=/usr/local/libexec/psif:</pre><p>You should also specify the <var class="LITERAL">rw</var> capability; that tells <bclass="APPLICATION">LPD</b> to open the printer in read-write mode.</p><p>If you have a parallel <span class="TRADEMARK">PostScript</span> printer (andtherefore cannot use two-way communication with the printer, which <ttclass="COMMAND">lprps</tt> needs), you can use the following shell script as the textfilter:</p><pre class="PROGRAMLISTING">#!/bin/sh##  psif - Print PostScript or plain text on a PostScript printer#  Script version; NOT the version that comes with lprps#  Installed in /usr/local/libexec/psif#IFS="" read -r first_linefirst_two_chars=`expr "$first_line" : '\(..\)'`if [ "$first_two_chars" = "%!" ]; then    #    #  PostScript job, print it.    #    echo "$first_line" &amp;&amp; cat &amp;&amp; printf "\004" &amp;&amp; exit 0    exit 2else    #    #  Plain text, convert it, then print it.    #    ( echo "$first_line"; cat ) | /usr/local/bin/textps &amp;&amp; printf "\004" &amp;&amp; exit 0    exit 2fi</pre><p>In the above script, <tt class="COMMAND">textps</tt> is a program we installedseparately to convert plain text to <span class="TRADEMARK">PostScript</span>. You canuse any text-to-<span class="TRADEMARK">PostScript</span> program you wish. The FreeBSDPorts Collection (see <a href="ports.html">The Ports Collection</a>) includes a fullfeatured text-to-<span class="TRADEMARK">PostScript</span> program called <varclass="LITERAL">a2ps</var> that you might want to investigate.</p></div><div class="SECT3"><h3 class="SECT3"><a id="PRINTING-ADVANCED-PS" name="PRINTING-ADVANCED-PS">9.4.1.3Simulating <span class="TRADEMARK">PostScript</span> on Non <spanclass="TRADEMARK">PostScript</span> Printers</a></h3><p><span class="TRADEMARK">PostScript</span> is the <span class="emphasis"><iclass="EMPHASIS">de facto</i></span> standard for high quality typesetting and printing.<span class="TRADEMARK">PostScript</span> is, however, an <span class="emphasis"><iclass="EMPHASIS">expensive</i></span> standard. Thankfully, Aladdin Enterprises has afree <span class="TRADEMARK">PostScript</span> work-alike called <bclass="APPLICATION">Ghostscript</b> that runs with FreeBSD. Ghostscript can read most<span class="TRADEMARK">PostScript</span> files and can render their pages onto a varietyof devices, including many brands of non-PostScript printers. By installing Ghostscriptand using a special text filter for your printer, you can make your non <spanclass="TRADEMARK">PostScript</span> printer act like a real <spanclass="TRADEMARK">PostScript</span> printer.</p><p>Ghostscript is in the FreeBSD Ports Collection, if you would like to install it fromthere. You can fetch, build, and install it quite easily yourself, as well.</p><p>To simulate <span class="TRADEMARK">PostScript</span>, we have the text filter detectif it is printing a <span class="TRADEMARK">PostScript</span> file. If it is not, thenthe filter will pass the file directly to the printer; otherwise, it will use Ghostscriptto first convert the file into a format the printer will understand.</p><p>Here is an example: the following script is a text filter for Hewlett Packard DeskJet500 printers. For other printers, substitute the <var class="OPTION">-sDEVICE</var>argument to the <tt class="COMMAND">gs</tt> (Ghostscript) command. (Type <ttclass="COMMAND">gs -h</tt> to get a list of devices the current installation ofGhostscript supports.)</p><pre class="PROGRAMLISTING">#!/bin/sh##  ifhp - Print Ghostscript-simulated PostScript on a DeskJet 500#  Installed in /usr/local/libexec/ifhp##  Treat LF as CR+LF (to avoid the "staircase effect" on HP/PCL#  printers):#printf "\033&amp;k2G" || exit 2##  Read first two characters of the file#IFS="" read -r first_linefirst_two_chars=`expr "$first_line" : '\(..\)'`if [ "$first_two_chars" = "%!" ]; then    #    #  It is PostScript; use Ghostscript to scan-convert and print it.    #    /usr/local/bin/gs -dSAFER -dNOPAUSE -q -sDEVICE=djet500 \      -sOutputFile=- - &amp;&amp; exit 0else    #    #  Plain text or HP/PCL, so just print it directly; print a form feed    #  at the end to eject the last page.    #    echo "$first_line" &amp;&amp; cat &amp;&amp; printf "\033&amp;l0H" &amp;&amp; exit 0fiexit 2</pre><p>Finally, you need to notify <b class="APPLICATION">LPD</b> of the filter via the <varclass="LITERAL">if</var> capability:</p><pre class="PROGRAMLISTING">:if=/usr/local/libexec/ifhp:</pre><p>That is it. You can type <tt class="COMMAND">lpr plain.text</tt> and <ttclass="FILENAME">lpr whatever.ps</tt> and both should print successfully.</p></div><div class="SECT3"><h3 class="SECT3"><a id="PRINTING-ADVANCED-CONVFILTERS"name="PRINTING-ADVANCED-CONVFILTERS">9.4.1.4 Conversion Filters</a></h3><p>After completing the simple setup described in <ahref="printing-intro-setup.html#PRINTING-SIMPLE">Simple Printer Setup</a>, the firstthing you will probably want to do is install conversion filters for your favorite fileformats (besides plain ASCII text).</p><div class="SECT4"><h4 class="SECT4"><a id="AEN11415" name="AEN11415">9.4.1.4.1 Why Install ConversionFilters?</a></h4><p>Conversion filters make printing various kinds of files easy. As an example, supposewe do a lot of work with the <b class="APPLICATION">TeX</b> typesetting system, and wehave a <span class="TRADEMARK">PostScript</span> printer. Every time we generate a DVIfile from <b class="APPLICATION">TeX</b>, we cannot print it directly until we convertthe DVI file into <span class="TRADEMARK">PostScript</span>. The command sequence goeslike this:</p><pre class="SCREEN"><samp class="PROMPT">%</samp> <kbd class="USERINPUT">dvips seaweed-analysis.dvi</kbd><samp class="PROMPT">%</samp> <kbd class="USERINPUT">lpr seaweed-analysis.ps</kbd></pre><p>By installing a conversion filter for DVI files, we can skip the hand conversion stepeach time by having <b class="APPLICATION">LPD</b> do it for us. Now, each time we get aDVI file, we are just one step away from printing it:</p><pre class="SCREEN"><samp class="PROMPT">%</samp> <kbd class="USERINPUT">lpr -d seaweed-analysis.dvi</kbd></pre><p>We got <b class="APPLICATION">LPD</b> to do the DVI file conversion for us byspecifying the <var class="OPTION">-d</var> option. Section <ahref="printing-using.html#PRINTING-LPR-OPTIONS-FORMAT">Formatting and ConversionOptions</a> lists the conversion options.</p><p>For each of the conversion options you want a printer to support, install a <spanclass="emphasis"><i class="EMPHASIS">conversion filter</i></span> and specify itspathname in <tt class="FILENAME">/etc/printcap</tt>. A conversion filter is like the textfilter for the simple printer setup (see section <ahref="printing-intro-setup.html#PRINTING-TEXTFILTER">Installing the Text Filter</a>)except that instead of printing plain text, the filter converts the file into a formatthe printer can understand.</p></div><div class="SECT4"><h4 class="SECT4"><a id="AEN11444" name="AEN11444">9.4.1.4.2 Which Conversions FiltersShould I Install?</a></h4><p>You should install the conversion filters you expect to use. If you print a lot of DVIdata, then a DVI conversion filter is in order. If you have got plenty of troff to printout, then you probably want a troff filter.</p><p>The following table summarizes the filters that <b class="APPLICATION">LPD</b> workswith, their capability entries for the <tt class="FILENAME">/etc/printcap</tt> file, andhow to invoke them with the <tt class="COMMAND">lpr</tt> command:</p><div class="INFORMALTABLE"><a id="AEN11451" name="AEN11451"></a><table border="0" frame="void" class="CALSTABLE"><col /><col /><col /><thead><tr><th>File type</th><th><tt class="FILENAME">/etc/printcap</tt> capability</th><th><tt class="COMMAND">lpr</tt> option</th></tr></thead><tbody><tr><td>cifplot</td><td><var class="LITERAL">cf</var></td><td><var class="OPTION">-c</var></td></tr><tr><td>DVI</td><td><var class="LITERAL">df</var></td><td><var class="OPTION">-d</var></td></tr><tr><td>plot</td><td><var class="LITERAL">gf</var></td><td><var class="OPTION">-g</var></td></tr><tr><td>ditroff</td><td><var class="LITERAL">nf</var></td><td><var class="OPTION">-n</var></td></tr><tr><td>FORTRAN text</td><td><var class="LITERAL">rf</var></td><td><var class="OPTION">-f</var></td></tr><tr><td>troff</td><td><var class="LITERAL">tf</var></td><td><var class="OPTION">-f</var></td></tr><tr><td>raster</td><td><var class="LITERAL">vf</var></td><td><var class="OPTION">-v</var></td></tr><tr><td>plain text</td><td><var class="LITERAL">if</var></td><td>none, <var class="OPTION">-p</var>, or <var class="OPTION">-l</var></td></tr></tbody></table></div><p>In our example, using <tt class="COMMAND">lpr -d</tt> means the printer needs a <varclass="LITERAL">df</var> capability in its entry in <ttclass="FILENAME">/etc/printcap</tt>.</p><p>Despite what others might contend, formats like FORTRAN text and plot are probablyobsolete. At your site, you can give new meanings to these or any of the formattingoptions just by installing custom filters. For example, suppose you would like todirectly print Printerleaf files (files from the Interleaf desktop publishing program),but will never print plot files. You could install a Printerleaf conversion filter underthe <var class="LITERAL">gf</var> capability and then educate your users that <ttclass="COMMAND">lpr -g</tt> mean ``print Printerleaf files.''</p></div><div class="SECT4"><h4 class="SECT4"><a id="AEN11520" name="AEN11520">9.4.1.4.3 Installing ConversionFilters</a></h4><p>Since conversion filters are programs you install outside of the base FreeBSDinstallation, they should probably go under <tt class="FILENAME">/usr/local</tt>. Thedirectory <tt class="FILENAME">/usr/local/libexec</tt> is a popular location, since theyare specialized programs that only <b class="APPLICATION">LPD</b> will run; regular usersshould not ever need to run them.</p><p>To enable a conversion filter, specify its pathname under the appropriate capabilityfor the destination printer in <tt class="FILENAME">/etc/printcap</tt>.</p>

⌨️ 快捷键说明

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