<!--  TODO
	- graphics printing
	- fonts
  -->

<!--	The Linux Printing Usage HOWTO
	v1.0 (c) 1995 Matt Foster
	Last revised 5 Aug 1995
  -->

<!doctype linuxdoc system>
<article>
<title>The Linux Printing Usage HOWTO
<author>by Matt Foster  &lt;mwf@engr.uark.edu&gt;
<date>v1.0, 5 August 1995

<sect>Introduction
<p>
This document describes how to use the line printer spooling system provided
with the Linux operating system.  If you are looking for a guide to setting
up your print environment, please see the Linux Printing Setup HOWTO.

<sect1>Linux Printing HOWTO History
<p>
This version of the Linux Printing HOWTO is a complete rewrite of the one
originally written by Grant Taylor &lt;grant@god.tufts.edu&gt; and Brian
McCauley &lt;B.A.McCauley@bham.ac.uk&gt;.  I have tried to keep with the
coverage of material presented by Grant and Brian's HOWTO, but I have
drastically modified the style of presentation and the depth of material
covered.  I feel that this makes the HOWTO more complete and easier to
read.  I can only hope that you agree.

<sect1>Copyrights and Trademarks
<p>
Some names mentioned in this HOWTO are claimed as copyrights and/or
trademarks of certain persons and/or companies.  These names appear
in full or initial caps in this HOWTO.
<p><p>
The Linux Printing Usage HOWTO v1.0 (c) 1995 Matt Foster.
<p><p>
Unless otherwise stated, Linux HOWTO documents are copyrighted by their
respective authors. Linux HOWTO documents may be reproduced and distributed 
in whole or in part, in any medium physical or electronic, as long as
this copyright notice is retained on all copies. Commercial redistribution 
is allowed and encouraged; however, the author would like to be notified of 
any such distributions. 
<p>
All translations, derivative works, or aggregate works incorporating 
any Linux HOWTO documents must be covered under this copyright notice. 
That is, you may not produce a derivative work from a HOWTO and impose
additional restrictions on its distribution. Exceptions to these rules
may be granted under certain conditions; please contact the Linux HOWTO
coordinator at the address given below.
<p>
In short, we wish to promote dissemination of this information through as
many channels as possible. However, we do wish to retain copyright on the
HOWTO documents, and would like to be notified of any plans to redistribute
the HOWTOs. 
<p>
If you have questions, please contact Greg Hankins, the Linux HOWTO 
coordinator, at &lt;gregh@sunsite.unc.edu&gt;. You may finger this address
for phone number and additional contact information. 

<sect1>Downloading the Linux Printing HOWTOs
<p>
I recommend that if you want to print a copy of this HOWTO that you 
download the PostScript version.  It is formatted in a fashion that is
aesthetically appealing and easier to read.  You can get the PostScript
version from one of the many Linux distribution sites (such as SunSITE
<url url="ftp://sunsite.unc.edu/Linux/docs/HOWTO/">), or directly from my
World Wide Web page at <url url="http://www.engr.uark.edu/~mwf/pht/">.

<sect1>Feedback
<p>
Questions, comments, or corrections for this HOWTO may be directed to
&lt;mwf@engr.uark.edu&gt;.

<sect1>Acknowledgments
<p>
Thanks go out to all of the people who took the time to read the alpha
version of this HOWTO and respond with many helpful comments and
suggestions--some of you may see your comments reflected in the version.
<p>
I would also like to thank Grant and Brian for the loads of information
that they have given me during the transition of authorship.

<sect>Printing Under Linux
<p>
This section discusses how to print files, examine the print queue, remove
jobs from the print queue, format files before printing them, and configure
your printing environment.

<sect1>History
<p>
The Linux printing system---the <em>lp</em> system---is a port of the source
code written by the Regents of the University of California for the Berkeley
Software Distribution version of the UNIX operating system.

<sect1>Basic Printing
<p>
By far, the most simplistic way to print in the Linux operating system is
to send the file to be printed directly to the printing device.  One way
to do this is to use the <em>cat</em> command.  As the <tt>root</tt> user,
one could do something like

<tscreen><verb>
# cat thesis.txt > /dev/lp
</verb></tscreen>

In this case, <tt>/dev/lp</tt> is a symbolic link to the actual printing
device--be it a dot-matrix, laser printer, typesetter, or plotter.  (See
<em>ln</em>(1) for more information on symbolic links.)
<p>
For the purpose of security, only the <tt>root</tt> user and users in the
same group as the print daemon are able to write directly to the printer.
This is why commands such as <em>lpr</em>, <em>lprm</em>, and <em>lpq</em>
have to be used to access the printer.
<p>
Because of this, users have to use <em>lpr</em> to print a file.  The
<em>lpr</em> command is responsible for taking care of all of the initial
work needed to print the file, and then it hands control over to another
program, <em>lpd</em>, the line printing daemon.  The line printing daemon then
tells the printer how to print the file.
<p>
When <em>lpr</em> is executed, it first copies the specified file to a certain
directory (the spool directory) where the file remains until <em>lpd</em>
prints it.  Once <em>lpd</em> is told that there is a file to print, it
will spawn a copy of itself (what we programmers call forking).  This copy
will print our file while the original copy waits for more requests.  This
allows for multiple jobs to be queued at once.
<p>
The syntax of <em>lpr</em>(1) is a very familiar one,

<tscreen><verb>
$ lpr [ options ] [ filename ... ]
</verb></tscreen>

If a <tt>filename</tt> is not specified, <em>lpr</em> assumes that the input
should come from standard input (usually the keyboard, or another program's
output).  This enables the user to redirect a command's output to the
printing device.  As such,

<tscreen><verb>
$ cat thesis.txt | lpr
</verb></tscreen>

or, something more powerful, like

<tscreen><verb>
$ pr -l60 thesis.txt | lpr
</verb></tscreen>

The <em>lpr</em> command accepts several command-line arguments that
allow a user to control how it works.  Some of the most widely used arguments
are: -<bf/P/printer specifies the printer to use, -<bf/h/ suppresses printing
of the burst page, -<bf/s/ creates a symbolic link instead of copying the
entire file to the spool directory (useful for large files), and -<bf/&num;/num
specifies the number of copies to print.  An example interaction with
<em>lpr</em> might be something like

<tscreen><verb>
$ lpr -#2 -sP dj thesis.txt
</verb></tscreen>

This command would create a symbolic link to the file <tt>thesis.txt</tt> in
the spool directory for the printer named <em>dj</em>, where it would be
processed by <em>lpd</em>.  It would then print a second copy of
<tt>thesis.txt</tt>.
<p>
For a listing of all the options that <em>lpr</em> will recognize, see
<em>lpr</em>(1).

<sect1>Viewing the Print Queue
<p>
Sometimes it is useful to know what jobs are currently in a particular
printer's queue.  This is the sole task of the <em>lpq</em> command.
<p>
To see what is in the queue of the default printer (as defined by
/etc/printcap), use

<tscreen><verb>
$ lpq
lp is ready and printing
Rank   Owner      Job  Files                            Total Size
active mwf	  31   thesis.txt			682048 bytes
</verb></tscreen>

<sect1>Canceling a Print Job
<p>
Another useful feature of any printing system is the ability to cancel a job
that has been previously queued.  To do this, use <em>lprm</em>.

<tscreen><verb>
$ lprm -
</verb></tscreen>

The above command cancels all of the print jobs that are owned by the user
who issued the command.  A single print job can be canceled by first getting
the job number as reported by <em>lpq</em>, and then giving that number to
<em>lprm</em>.  For example,

<tscreen><verb>
$ lprm 31
</verb></tscreen>

would cancel job 31 (<em>thesis.txt</em>) on the default printer.

<sect>Miscellaneous Items
<p>
This section discusses some of the miscellaneous things that you may
want to know about printing under Linux.

<sect1>Formatting
<p>
Since most ASCII files are not formatted for printing, it is useful to format
them in some way before they are actually printed.  This may include putting
a title and page number on each page, setting the margins, double spacing,
indenting, or printing a file in multiple columns.  A common way to do this
is to use a print preprocessor such as <em>pr</em>.  

<tscreen><verb>
$ pr +4 -d -h"Ph.D. Thesis, 2nd Draft" -l60 thesis.txt | lpr
</verb></tscreen>

In the above example, <em>pr</em> would take the file thesis.txt and
skip the first three pages (+4), set the page length to sixty lines (-l60),
double space the output (-d), and add the phrase "Ph.D. Thesis, 2nd Draft"
to the top of each page (-h).  <em>Lpr</em> would then print <em>pr</em>'s
output.  See its on-line manual page for more information on using <em>pr</em>.

<sect1>The PRINTER Environment Variables
<p>
All of the commands in the Linux printing system accept the -<bf/P/ option.
This option allows the user to specify which printer to use for output.  If
a user doesn't specify which printer to use, then the default printer will
be assumed as the output device.
<p>
Instead of having to specify a printer to use every time that you print, you
can set the PRINTER environment variable to the name of the printer that you
want to use.  This is accomplished in different ways for each shell.  For
<em>bash</em> you can do this with

<tscreen><verb>
$ PRINTER="printer_name"; export PRINTER
</verb></tscreen>

in <em>csh</em>, you can do it with

<tscreen><verb>
% setenv PRINTER "printer_name"
</verb></tscreen>

These commands can be placed in your login scripts (.profile or .cshrc),
or issued on the command-line.  (See <em>bash</em>(1) and <em>csh</em>(1)
for more information on environment variables.)

<sect1>Printing PostScript files
<p>
Printing PostScript files on a printer that has a PostScript interpreter
is simple; just use <em>lpr</em>, and the printer will take care of all
of the details for you.  For those of us that don't have printers with
PostScript capabilities, we have to resort to other means.  Luckily, there
are programs available that can make sense of PostScript, and translate
it into a language that most printers will understand.  Probably the most
well known of these programs is Ghostscript.
<p>
Ghostscript's responsibility is to convert all of the descriptions in a
PostScript file to commands that the printer will understand.  To print
a PostScript file using Ghostscript, you might do something like

<tscreen><verb>
$ gs -dNOPAUSE -sDEVICE=deskjet -sOutputFile=|lpr thesis.ps
</verb></tscreen>

Notice in the above example that we are actually piping the output of
Ghostscript to the <em>lpr</em> command by using the -<bf/sOutputFile/
option.

Ghostview is an interface to Ghostscript for the X Window System.  It allows
you to preview a PostScript file before you print it.  Ghostview and
Ghostscript can both be downloaded from
<url url="ftp://prep.ai.mit.edu/pub/gnu/">.

<sect1>Printing TeX files
<p>
One of the easiest ways to print TeX files is to convert them to PostScript
and then print them using Ghostscript.  To do this, you first need to convert
them from TeX to a format known as DVI (which stands for device-independent).
You can do this with the <em>tex</em>(1) command.  Then you need to convert
the DVI file to a PostScript file using <em>dvips</em>.  All of this would look
like the following when typed in.

<tscreen><verb>
$ tex thesis.tex
$ dvips thesis.dvi
</verb></tscreen>

Now you are ready to print the resulting PostScript file as described above.

<sect1>Printing <tt>troff</tt> formatted files
<p>

<tscreen><verb>
$ groff -Tascii thesis.tr | lpr
</verb></tscreen>

or, if you prefer,

<tscreen><verb>
$ groff thesis.tr > thesis.ps
</verb></tscreen>

and then print the PostScript file as described above.

<sect>Answers to Frequently Asked Questions
<p><p>
Q1.  How do I prevent the staircase effect?
<p>
A1.  The staircase effect is caused by the way some printers expect lines to
be terminated.  Some printers want lines that end with a carriage-return/line-feed
sequence (DOS-style) instead of the default line-feed sequence used
for UNIX-type systems.  The easiest way to fix this is to see if your printer
can switch between the two styles somehow---either by flipping a DIP switch, or
by sending an escape sequence at the start of each print job.  To do the latter,
you need to create a filter (see Q2 and [Foster95b]).

A quick fix is to use a filter on the command-line.  An example of this might
be

<tscreen><verb>
$ cat thesis.txt | todos | lpr
</verb></tscreen>

<p>
Q2.  What is a filter?
<p>
A2.  A filter is a program that reads from standard input (<em>stdin</em>),
performs some action on this input, and writes to standard output
(<em>stdout</em>).  Filters are used for a lot of things, including text
processing.
<p><p>
Q3.  What is a <em>magic</em> filter?
<p>
A3.  A magic filter is a filter that performs an action based on a file's
type.  For example, if the file is a plain, text file, it would simply
print the file using the normal methods.  If the file is a PostScript
file, or any other format, it would print it using another method (ghostscript).

<sect>Troubleshooting
<p>
This section covers some common things that can go wrong with your printing
system.  Send suggestions for this section to &lt;mwf@engr.uark.edu&gt;.

<sect>References
<p>
This is a section of references on the Linux printing system.  I have
tried to keep the references section of this HOWTO as focused as
possible.  If you feel that I have forgotten a significant reference
work, please do not hesitate to contact me.
<p>
Before you post your question to a USENET group, consider the following:
<itemize>
  <item>Is the printer accepting jobs?  (Use <em>lpc</em>(8) to verify.)
  <item>Is the answer to your question covered in this HOWTO, or the Printing
Setup HOWTO?
</itemize>
<p>
If any of the above are true, you may want to think twice before you post
your question.  And, when you do finally post to a newsgroup, try to include
pertinent information.  Try not to just say something like, "I'm having
trouble with lpr, please help."  These types of posts will most definitely
be ignored by many.  Also try to include the kernel version that you're
running, how the error occured, and, if any, the specific error message that
the system returned.

<descrip>
<tag>Welsh, Matt.  <em>Linux Installation and Getting Started</em></tag> an
excellent introductory text for the beginning Linux user
<p>
<tag>Foster, Matt.  <em>Linux Printing Setup HOWTO</em></tag> the supplement
to this HOWTO; covers topics such as setting up, and configuring the print
software
<p>
<tag>On-Line Manual Pages</tag>
  <itemize>
    <item><em>cat</em>(1)  concatenate and print files
    <item><em>dvips</em>(1)  convert a TeX DVI file to PostScript
    <item><em>ghostview</em>(1)  view PostScript documents using Ghostscript
    <item><em>groff</em>(1)  front-end for the groff document formatting system
    <item><em>gs</em>(1)  Ghostscript interpreter/viewer
    <item><em>lpc</em>(8)  line printer control program
    <item><em>lpd</em>(8)  line printer spooler daemon
    <item><em>lpq</em>(1)  spool queue examination program
    <item><em>lpr</em>(1)  off-line printer
    <item><em>lprm</em>(1)  remove jobs from the line printer spooling queue
    <item><em>pr</em>(1)  convert text files for printing
    <item><em>tex</em>(1)  text formatting and typesetting
  </itemize>
<p>
<tag>USENET newsgroups</tag>
  <itemize>
    <item><tt>comp.os.linux.*</tt>  a plethora of information on Linux
    <item><tt>comp.unix.*</tt>  discussions relating to the UNIX operating system
  </itemize>
</descrip>

<sect>Colophon
<p>
This HOWTO was written using <em>vi</em>, the ultimate editor; the human
mind, the ultimate computer; and imagination, the ultimate power tool.  The
computer of choice was a Gateway2000 i486/50 running the Slackware 2.2
distribution of Linux with version 1.3.4 of the kernel.  The original document
was written in mark-up format using Linuxdoc-SGML (a hacked version of Tom
Gordon's QWERTZ DTD).  The HOWTO was then emailed to Greg Hankins, the Linux
Documentation Project coordinator.  There it was converted to PostScript,
TeXinfo, DVI, ASCII, and HTML formats.  Finally it was posted on USENET, and
placed in the Linux archives found on the SunSITE FTP/WWW servers for easy
Internet access.
</article>
