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

📄 ch20.htm

📁 linux-unix130.linux.and.unix.ebooks130 linux and unix ebookslinuxLearning Linux - Collection of 12 E
💻 HTM
📖 第 1 页 / 共 3 页
字号:


<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<SCRIPT>
<!--
function displayWindow(url, width, height) {
        var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>

 -->






 











 

















<center><H1>Printing</H1></center>







<UL>



	<LI><A HREF="#Heading1">- 20 -</A>



	<UL>



		<LI><A HREF="#Heading2">Printing</A>



		<UL>



			<LI><A HREF="#Heading3">Where to Start</A>



			<LI><A HREF="#Heading4">Printing Plain Text Files</A>



			<LI><A HREF="#Heading5">Hardware and Drivers</A>



			<LI><A HREF="#Heading6">Printer Device Names</A>



			<LI><A HREF="#Heading7">The Infamous lpr, lpd, and lpc Commands</A>



			<LI><A HREF="#Heading8">The /etc/printcap File</A>



			<LI><A HREF="#Heading9">How It All Fits</A>



			<LI><A HREF="#Heading10">Listing 20.1. A sample /etc/printcap file.</A>



			<UL>



				<LI><A HREF="#Heading11">The Staircase Effect</A>



			</UL>



			<LI><A HREF="#Heading12">PostScript Support</A>



			<UL>



				<LI><A HREF="#Heading13">Printing DVI Files</A>



			</UL>



			<LI><A HREF="#Heading14">Summary</A>



		</UL>



	</UL>



</UL>







<P>



<HR SIZE="4">







<H2 ALIGN="CENTER"><A NAME="Heading1<FONT COLOR="#000077">- 20 -</FONT></H2>



<H2 ALIGN="CENTER"><A NAME="Heading2<FONT COLOR="#000077">Printing</FONT></H2>



<P><I>by Kamran Husain</I></P>







<P>IN THIS CHAPTER</P>







<UL>



	<LI>Where to Start 



	<P>



	<LI>Printing Plain Text Files 



	<P>



	<LI>Hardware and Drivers 



	<P>



	<LI>Printer Device Names 



	<P>



	<LI>The Infamous lpr, lpd, and<TT> </TT>lpc<TT> </TT>Commands 



	<P>



	<LI>The /etc/printcap File 



	<P>



	<LI>How It All Fits 



	<P>



	<LI>PostScript Support  



</UL>







<P><BR>



This chapter introduces you to the topic of using the print facilities under Linux.



We will cover the following topics:







<UL>



	<LI>Printing files under Linux



	<P>



	<LI>Getting the correct drivers for your hardware



	<P>



	<LI>An introduction to printer device names



	<P>



	<LI>Using the infamous <TT>lpr</TT>, <TT>lpd</TT>, and <TT>lpc</TT> commands



	<P>



	<LI>Working with the <TT>/etc/printcap</TT> file



	<P>



	<LI>How printing really works under Linux



	<P>



	<LI>Using a PostScript printer with DVI support



</UL>







<H3 ALIGN="CENTER"><A NAME="Heading3<FONT COLOR="#000077">Where to Start</FONT></H3>



<P>If you are reading this chapter after being frustrated with the efforts of getting



even a text file printed from Linux, you are at the right chapter.</P>



<P>On the other hand, if you have not even begun to deal with the act of printing



from Linux to your printer, consider yourself lucky to have saved some time. Why,



you ask? Well, chances are the default kernel you are booting with does not have



printing enabled in it. If the capability is not there, you have to rebuild the kernel.



How to rebuild and install the kernel has been dealt with in detail in Chapter 5,



&quot;Special Installations.&quot; All you have to remember is that you have to answer



&quot;y&quot; (for yes) when asked whether you want printing enabled. The first time



you build your kernel, the default is &quot;n&quot; (for no, don't build it). In



later versions of the kernel, this option will be set to &quot;y,&quot; but don't



hold your breath just yet.</P>



<P>Once you have rebuilt and installed your kernel, you should be able to <TT>cat</TT>



files to the <TT>/dev/lp</TT> or use the standard UNIX command <TT>lpr</TT> to print



out the parallel or serial printer port on your PC.</P>



<P>If you have a serial printer, your printer will be one of the devices called <TT>/dev/ttyS?</TT>,



<TT>/dev/ttys?</TT>, or <TT>/dev/cua?</TT>. If you have your printer hooked to the



parallel, the devices would be <TT>/dev/lp0</TT>, and so on. Typing <TT>cat file



&gt;/dev/</TT>???? should force what you type to the printer, where the question



marks signify the device name. You may have to be logged in as <TT>root</TT> to be



able to write to the printing device, because these ports usually have a restricted



number of processes with write permission.



<H3 ALIGN="CENTER"><A NAME="Heading4<FONT COLOR="#000077">Printing Plain Text



Files</FONT></H3>



<P>Most plain text files in the UNIX world are boring. No page numbers, line breaks,



formatting information, or logical page breaks. If you have a dot matrix printer,



the output can cross over the perforations. The output on the pages can be flushed



way to the left, making it look lopsided with extra spacing on the right side of



the page.</P>



<P>For this reason, it's a good idea to send the text file through a program called



a formatter. A simple formatter on Linux and UNIX is the <TT>pr</TT> command. The



<TT>pr</TT> command is designed to format plain text for printing using a lineprinter.



With <TT>pr</TT> you can add headers, footers, page numbers, date, margins, double



spaced lines, and so on. If you are a DOS user, you can think of the <TT>pr</TT>



command as the PRINT command--in other words, a simple print utility.



<H3 ALIGN="CENTER"><A NAME="Heading5<FONT COLOR="#000077">Hardware and Drivers</FONT></H3>



<P>We briefly touched the topic of printer drivers not being included in the default



kernel. This section gives a little bit more detail on how to select your driver.



There are two ways the kernel driver may be used to run the parallel printer ports.



The first method, the original, is the polling driver. You will see this polling



method used most often in most UNIX systems. The other method, the kernel driver,



which may be used to run the parallel printer ports, is the interrupt driver. In



principle, the interrupt driver only deals with the port when it gets an interrupt



and should therefore be more efficient. In practice, people have found that efficiency



depends on the type of machine. Selecting one or the other probably doesn't make



too much difference in most situations.</P>



<P>For the polling driver, you may adjust its polling frequency with the program



<TT>tunelp</TT> without kernel twiddling. The actual driver is in the kernel source



file <TT>lp.c</TT>. To choose the interrupt driver instead of the polled, use the



program <TT>tunelp</TT> to set it. You can get <TT>tunelp</TT> from the CD as part



of the installation process or from the <TT>sunsite</TT> archives at <TT>/pub/Linux/system/Printing/



tunelp-1.0.tar.Z</TT>.



<H3 ALIGN="CENTER"><A NAME="Heading6<FONT COLOR="#000077">Printer Device Names</FONT></H3>



<P>On an XT bus system, LPT1: becomes <TT>/dev/lp0</TT> (<TT>major=6</TT>, <TT>minor=0</TT>);



on an AT system, LPT1: becomes <TT>/dev/lp1</TT> (<TT>major=6</TT>, <TT>minor=1</TT>).



See Table 20.1 for device numbers for printers on Linux. See Chapter 57, &quot;Device



Drivers,&quot; for a description of what major and minor mean. Basically, major refers



to type of device and minor refers to the actual device if more than one device type



can exist on the same machine. So if you have two parallel ports, the first is referred



to with <TT>major=6</TT>, and the next as <TT>minor=0</TT>. <BR>







<CENTER>



<P><FONT SIZE="4"><B>Table 20.1. Device numbers for printers on Linux. </B></FONT>



<TABLE BORDER="0">



	<TR ALIGN="LEFT" rowspan="1">



		<TD ALIGN="LEFT"><I>Name </I></TD>



		<TD ALIGN="LEFT"><I>Major </I></TD>



		<TD ALIGN="LEFT"><I>Minor </I></TD>



		<TD ALIGN="LEFT"><I>I/O address </I></TD>



	</TR>



	<TR ALIGN="LEFT" rowspan="1">



		<TD ALIGN="LEFT"><TT>lp0</TT> </TD>



		<TD ALIGN="LEFT"><TT>6</TT> </TD>



		<TD ALIGN="LEFT"><TT>0</TT> </TD>



		<TD ALIGN="LEFT">0x3bc </TD>



	</TR>



	<TR ALIGN="LEFT" rowspan="1">



		<TD ALIGN="LEFT"><TT>lp1</TT> </TD>



		<TD ALIGN="LEFT"><TT>6</TT> </TD>



		<TD ALIGN="LEFT"><TT>1</TT> </TD>



		<TD ALIGN="LEFT">0x378 </TD>



	</TR>



	<TR ALIGN="LEFT" rowspan="1">



		<TD ALIGN="LEFT"><TT>lp2</TT> </TD>



		<TD ALIGN="LEFT"><TT>6</TT> </TD>



		<TD ALIGN="LEFT"><TT>2</TT> </TD>



		<TD ALIGN="LEFT">0x278 </TD>



	</TR>



</TABLE>







</CENTER>



<P><BR>



For a serial printer, use the <TT>/dev/ttyS</TT>? or <TT>/devttys</TT>? device. Don't



use the <TT>/dev/cua</TT>? device for serial printing, because these are usually



reserved for modems. The <TT>/dev/ttyS</TT>? devices have major=<TT>4</TT> and the



<TT>/dev/cua</TT>? devices have major=<TT>5</TT>.



<CENTER>



<H3><A NAME="Heading7<FONT COLOR="#000077">The Infamous lpr, lpd, and lpc Commands</FONT></H3>



</CENTER>



<P>The <TT>lpr</TT>, <TT>lpd</TT>, and <TT>lpc</TT> commands are perhaps the programs



hated the most by novices in the Linux community. If everything falls in place with



these programs, you are set. If something is wrong, you have to know how these commands



work together to get printing up and running.</P>



<P>You can always print directly to the printer by using the following command:<FONT



COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">ls &gt; /dev/lp0



</FONT></PRE>



<P>Unfortunately, this command can interfere with other users trying to print. Also,



this command may not even work if the computer is not able to time the sending of



characters to the lineprinter correctly. On a slow printer, or a printer which is

⌨️ 快捷键说明

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