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

📄 ch43_22.htm

📁 the unix power tools
💻 HTM
字号:
<HTML><!--Distributed by F --><HEAD><TITLE>[Chapter 43] 43.22 Converting Text Files to PostScript </TITLE><METANAME="DC.title"CONTENT="UNIX Power Tools"><METANAME="DC.creator"CONTENT="Jerry Peek, Tim O'Reilly &amp; Mike Loukides"><METANAME="DC.publisher"CONTENT="O'Reilly &amp; Associates, Inc."><METANAME="DC.date"CONTENT="1998-10-23T15:52:08Z"><METANAME="DC.type"CONTENT="Text.Monograph"><METANAME="DC.format"CONTENT="text/html"SCHEME="MIME"><METANAME="DC.source"CONTENT="1-56592-260-3"SCHEME="ISBN"><METANAME="DC.language"CONTENT="en-US"><METANAME="generator"CONTENT="Jade 1.1/O'Reilly DocBook 3.0 to HTML 4.0"><LINKREV="made"HREF="mailto:online-books@oreilly.com"TITLE="Online Books Comments"><LINKREL="up"HREF="ch43_01.htm"TITLE="43. Printing"><LINKREL="prev"HREF="ch43_21.htm"TITLE="43.21 Preprocessing troff Input with sed "><LINKREL="next"HREF="ch43_23.htm"TITLE="43.23 psselect: Print Some Pages from a PostScript file"></HEAD><BODYBGCOLOR="#FFFFFF"TEXT="#000000"><DIVCLASS="htmlnav"><H1><IMGSRC="gifs/smbanner.gif"ALT="UNIX Power Tools"USEMAP="#srchmap"BORDER="0"></H1><MAPNAME="srchmap"><AREASHAPE="RECT"COORDS="0,0,466,58"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="467,0,514,18"HREF="jobjects/fsearch.htm"ALT="Search this book"></MAP><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch43_21.htm"TITLE="43.21 Preprocessing troff Input with sed "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 43.21 Preprocessing troff Input with sed "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><B><FONTFACE="ARIEL,HELVETICA,HELV,SANSERIF"SIZE="-1">Chapter 43<BR>Printing</FONT></B></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch43_23.htm"TITLE="43.23 psselect: Print Some Pages from a PostScript file"><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 43.23 psselect: Print Some Pages from a PostScript file"BORDER="0"></A></TD></TR></TABLE>&nbsp;<HRALIGN="LEFT"WIDTH="515"TITLE="footer"></DIV><DIVCLASS="SECT1"><H2CLASS="sect1"><ACLASS="title"NAME="UPT-ART-2500">43.22 Converting Text Files to PostScript </A></H2><PCLASS="para">Printing used to be easy; when all we had were daisy wheel printersand line printers, you could send virtually any text file to a printerwithout modification.That's no longer possible; fancy&quot;printer languages&quot; like PostScript force you to do a fair amount ofprocessing to get a simple text into some form that the printer canunderstand.</P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-48854"></A>As always, there are several ways to solve this problem.The first isgross and disgusting, but quite effective.Assume that you have a working version of <EMCLASS="emphasis">troff</EM>with the <EMCLASS="emphasis">-ms</EM> macros.Here's the script:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen"># the name of the script that runs troff for youroff=lw# choose your favorite macro packagemacros=-mssed -e '1i\.DS.in 0\.ft CW\.ps 10\.vs 12s/\\/\\e/gs/^/\\\&amp;/$a\.DE ' | $roff $macros</PRE></BLOCKQUOTE></P><PCLASS="para">How does it work?  It just &quot;wraps&quot; your text with a <EMCLASS="emphasis">troff</EM>incantation that prints the text in a fixed-width font, with no&quot;justification&quot; or &quot;fill.&quot; It relies on the <EMCLASS="emphasis">ms</EM> macro package tohandle margins, new lines, page numbers, and so on. The <EMCLASS="emphasis">sed</EM>script also massages your file so that it will print anything that<EMCLASS="emphasis">troff</EM> finds confusing&nbsp;- in particular, backslashes and linesbeginning with periods or single quotation marks. In fact, it can evenprint a <EMCLASS="emphasis">troff</EM> macro package; if memory serves me, that's why Ioriginally wrote it.</P><PCLASS="para">I like this because it works as well as any other solution I've seen,and better than most; it's extremely simple; and, because it usesUNIX tools to do the work they were designed to do, it's a gooddemonstration of the UNIX philosophy.  It's even elegantin itsown bizarre way.  And, if you know a little bit (not much) about<EMCLASS="emphasis">troff</EM>, you can customize it for your own situation.</P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-48870"></A><ACLASS="indexterm"NAME="AUTOID-48872"></A><ACLASS="indexterm"NAME="AUTOID-48875"></A>However, there are other solutions.Perhaps the best is to use the<EMCLASS="emphasis">enscript</EM> program, which is part of Adobe's <EMCLASS="emphasis">transcript</EM>package.That's proprietary software, so we can't include it withthis book.But at least we can point you in the right direction.</P><TABLECLASS="para.programreference"BORDER="1"><TR><THVALIGN="TOP"><ACLASS="programreference"HREF="examples/index.htm"TITLE="pstext">pstext</A><BR></TH><TDVALIGN="TOP"><ACLASS="indexterm"NAME="AUTOID-48882"></A>One option that's &quot;free&quot; is Dan Judd's <EMCLASS="emphasis">pstext</EM>program.Though it's small, it provides a lot of features.Itemulates a standard line printer: it interprets form feeds as pagebreaks, handles backspaces and tabs appropriately, lets you vary themargin, the number of lines per page, and so on.Here'show to use it:</TD></TR></TABLE><PCLASS="para"><TABLECLASS="screen.co"BORDER="1"><TR><THVALIGN="TOP"><PRECLASS="calloutlist"><ACLASS="co"HREF="ch43_02.htm"TITLE="43.2 Introduction to Printing on UNIX ">lpr</A> </PRE></TH><TDVALIGN="TOP"><PRECLASS="screen">% <CODECLASS="userinput"><B>pstext </B></CODE><CODECLASS="replaceable"><I>options file1 file2 ... </I></CODE><CODECLASS="userinput"><B>| lpr</B></CODE></PRE></TD></TR></TABLE></P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-48892"></A><ACLASS="indexterm"NAME="AUTOID-48895"></A>There are a zillionoptions, but the most important are:</P><DLCLASS="variablelist"><DTCLASS="term"><BCLASS="emphasis.bold">-l</B></DT><DDCLASS="listitem"><PCLASS="para">Print &quot;landscape&quot; (across the page, the long way); by default,printing is &quot;portrait&quot; (down the page).</P></DD><DTCLASS="term"><BCLASS="emphasis.bold">-ld</B></DT><DDCLASS="listitem"><PCLASS="para">Print landscape, &quot;two-up&quot; (two logical pages per physical page)-nottoo useful, unless your source file has short lines.</P></DD><DTCLASS="term"><BCLASS="emphasis.bold">-d</B></DT><DDCLASS="listitem"><PCLASS="para">Print portrait, &quot;two up.&quot;</P></DD><DTCLASS="term"><BCLASS="emphasis.bold">-s </B><CODECLASS="userinput"><B>p</B></CODE></DT><DDCLASS="listitem"><PCLASS="para">Use a font of size <EMCLASS="emphasis">p</EM> (in points).</P></DD><DTCLASS="term"><BCLASS="emphasis.bold">-f </B><CODECLASS="userinput"><B>name</B></CODE></DT><DDCLASS="listitem"><PCLASS="para">Use the font with the given <EMCLASS="emphasis">name</EM>.</P></DD><DTCLASS="term"><BCLASS="emphasis.bold">-n </B><CODECLASS="userinput"><B>n</B></CODE></DT><DDCLASS="listitem"><PCLASS="para">Print <EMCLASS="emphasis">n</EM> lines per page.</P></DD></DL><DIVCLASS="sect1info"><PCLASS="SECT1INFO">- <SPANCLASS="authorinitials">ML</SPAN></P></DIV></DIV><DIVCLASS="htmlnav"><P></P><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch43_21.htm"TITLE="43.21 Preprocessing troff Input with sed "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 43.21 Preprocessing troff Input with sed "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="book"HREF="index.htm"TITLE="UNIX Power Tools"><IMGSRC="gifs/txthome.gif"SRC="gifs/txthome.gif"ALT="UNIX Power Tools"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch43_23.htm"TITLE="43.23 psselect: Print Some Pages from a PostScript file"><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 43.23 psselect: Print Some Pages from a PostScript file"BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">43.21 Preprocessing troff Input with sed </TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="index"HREF="index/idx_0.htm"TITLE="Book Index"><IMGSRC="gifs/index.gif"SRC="gifs/index.gif"ALT="Book Index"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172">43.23 psselect: Print Some Pages from a PostScript file</TD></TR></TABLE><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><IMGSRC="gifs/smnavbar.gif"SRC="gifs/smnavbar.gif"USEMAP="#map"BORDER="0"ALT="The UNIX CD Bookshelf Navigation"><MAPNAME="map"><AREASHAPE="RECT"COORDS="0,0,73,21"HREF="../index.htm"ALT="The UNIX CD Bookshelf"><AREASHAPE="RECT"COORDS="74,0,163,21"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="164,0,257,21"HREF="../unixnut/index.htm"ALT="UNIX in a Nutshell"><AREASHAPE="RECT"COORDS="258,0,321,21"HREF="../vi/index.htm"ALT="Learning the vi Editor"><AREASHAPE="RECT"COORDS="322,0,378,21"HREF="../sedawk/index.htm"ALT="sed &amp; awk"><AREASHAPE="RECT"COORDS="379,0,438,21"HREF="../ksh/index.htm"ALT="Learning the Korn Shell"><AREASHAPE="RECT"COORDS="439,0,514,21"HREF="../lrnunix/index.htm"ALT="Learning the UNIX Operating System"></MAP></DIV></BODY></HTML>

⌨️ 快捷键说明

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