[<--] [Cover] [Table of Contents] [Concept Index] [Program Index] [-->] |
Debian: `magicfilter'
The usual way to print on a Linux system is to send a print job to the
printer with lpr
, as described below in Sending a Print Job to the Printer.
But you don't always send a file straight to the printer -- sometimes you may want to add special things to it before you print it, such as headers or graphic trim. For example, you might want to split a text file into pages and add a header to the top of each page containing the file name and page number; all of this is described in Formatting Text.
Sometimes you may need to convert or otherwise prepare a file so that it can be printed on your particular printer, since not all print hardware can print the same kinds of file formats. Recipes in this chapter show how to do this, such as how to convert PostScript files so that they will print properly on a non-PostScript printer (see Preparing Files for Printing).
This chapter also shows how to format PostScript files for printing. To convert plain text to PostScript and enhance it for printing, by adding fonts, graphic headers, and the like, see Converting Plain Text for Output.
And this chapter isn't in the files section, because you can print
things that aren't in a file -- for example, you can pipe the output of
another tool or series of tools to lpr
, and it will spool that
command output to the printer. This usage is actually very common.
NOTE: When a printer is properly configured on Linux, it is a pleasure to use, but a misconfigured printer can lead to all kinds of trouble -- including the dreaded "staircase effect," where a text file prints with each subsequent line of output offset to the right by the length of the previous line.
If print services haven't been configured yet on your system, I strongly recommend that the `magicfilter' package be installed; it includes filters for the automatic detection of file types -- when you print a file, it automatically converts it to the proper format for your printer.
Comprehensive details on the setup of printer resources can be found in both the Printing HOWTO and the Printing Usage HOWTO (see Reading System Documentation and Help Files).
The traditional way to print on Linux-based systems is to send a print job for the file or data you want to print to the spool queue for the printer in question. The spool queue contains all of the print jobs sent to it by all users; these jobs are released in turn to the printer device as it becomes available. In this way, Linux can handle multiple print jobs going to the same printer at once.
The following recipes show how to make and manage print jobs. In practice, you will probably send print jobs all the time -- since this is the way most printing is done in Linux -- and use the tools for listing or cancelling print jobs rarely. But sometimes things do go wrong, and it helps to know what to do when that happens.
Use lpr
to send a print job to the printer -- give the name of the
file to print as an argument. (You can also pipe the output of a command
to lpr
.)
lpr
writes a copy of the specified file or text to the spool
queue of the specified printer, to be sent to the printer when the
printer becomes available.
$ lpr invoice [RET]
banner
and send it to the printer, type:
$ banner "Bon voyage!" | lpr [RET]
$ ls -lR /usr/doc/HOWTO | lpr [RET]
If you have more than one printer connected to your system, specify the
printer to send to as an argument to the `-P' option. (Printers
have names just as user accounts and hosts do, and it is the
administrator's privilege to name them; the default printer is usually
called lp
, for "line printer.")
bossomatic
, type:
$ lpr -P bossomatic nightly-report [RET]
NOTE: The name of the lpr
tool comes from "line
printer," which was the kind of printer hardware in popular use back
when this program was first developed.
To print more than one copy of a print job, give the number of copies to
print as an argument to the `-#' option of lpr
.
$ lpr -#12 nightly-report [RET]
To list your print jobs, use lpq
, the "line printer queue"
tool. It outputs a list of all print jobs currently in the default
printer's spool queue -- each on a line of its own -- giving its rank in
the queue, the username who sent the job, the print job number, the file
names in the job, and the size of the data to be printed, in bytes.
$ lpq [RET] lp is ready and printing Rank Owner Job Files Total Size active groucho 83 cigar.ps 1739030 bytes 1st harpo 84 harp.ps 499 bytes 2nd chico 85 love.ps 45576 bytes $
In this example, there are three jobs queued for the default
printer -- one by user groucho
, for the file `cigar.ps', one
by user harpo
, for the file `harp.ps', and one by user
chico
, who has printed a file called `love.ps'.
The job by user groucho
is the active job; this is the job
that is currently printing on the printer. The other jobs must wait
until this file is finished printing, and then they print in rank order.
As with lpr
, you can specify the name of a printer as an argument
to the `-P' option.
bossomatic
, type:
$ lpq -P bossomatic [RET]
To only list the jobs for a particular user, give the name of the user as an argument.
harpo
, type:
$ lpq harpo [RET]
NOTE: When there are no print jobs, lpq
outputs the text
`no entries'.
To cancel a print job and remove it from the spool queue, use
lprm
, the "line printer remove" tool. Give as an argument the
number of the print job to remove.
$ lprm 83 [RET]
To cancel all of your print jobs in the spool queue, use a hyphen instead of the number of a print job.
$ lprm - [RET]
NOTE: If you try to cancel an active job -- one that has already been spooled to the printer -- don't be alarmed if some pages still print; the printer probably has some of the job in its internal print buffer. To stop the printing in a case like this, take the printer offline, reset it, and then put it back online again (usually, the printer will have buttons for these commands on its front control panel).
Another way of printing besides making a print job is to print from within an application.
Not all applications have print controls, but some of them
do -- including Emacs and LyX (see LyX Document Processing). Their print commands essentially send the print job to the
printer via lpr
, after possibly formatting or otherwise preparing
the data to print. If you are working in such an application and want to
print your work, using the built-in print control can be easier than
having to go to a shell to run lpr
.
For example, to print the current document in the LyX document
processing application, choose Print
from the File
menu;
it creates the proper output for your printer and makes a print job
containing this output (see LyX Document Processing).
Some tools, such as dvips
and enscript
(see Converting Plain Text for Output), are also configured to spool output
to the printer.
You can view these print jobs in the spool queue and you can cancel them, just as you could any print job.
To print the current buffer in Emacs, choose Print Buffer
from
the Print
submenu, found off the Tools
menu on the menu
bar. Another option on the print submenu is Print Region
, which
just prints the text between point and the mark (see Getting Acquainted with Emacs). Both commands print the hardcopy output
separated into pages, and with headers at the top of each page, showing
the file name and current page number.
To generate and print a PostScript image of the buffer, use the
ps-print-buffer
function, which is also available on the
Print
submenu. A related function, ps-print-region
,
prints a PostScript image of the region. These commands are useful for
sending the text of a buffer to a PostScript printer.
You can also run any of these functions by specifying them with the
M-x command; additionally, the lpr-buffer
and
lpr-region
functions send the buffer and region to lpr
without paginating the text or inserting headers.
M-x print-buffer [RET]
M-x lpr-buffer [RET]
M-x ps-print-buffer [RET]
You can print a DVI file directly with the dvips
tool -- omit the
`-o' option that is used to specify an output file, and it will
send the PostScript output directly to the spool queue of the default
printer.
$ dvips list.dvi [RET]
The following table lists some of dvips
's various options for
controlling print output.
OPTION | DESCRIPTION |
-A |
Print only odd-numbered pages (DVI file must have been generated by TeX). |
-B |
Print only even-numbered pages (DVI file must have been generated by TeX). |
-b copies |
Specify the number of copies to print -- useful for printing multiple copies of flyers, posters, signs, and the like. |
-k |
Print crop marks. |
-l last |
Specify the last page number to print. |
-m |
Use the manual feed tray. |
-p first |
Specify the first page to begin printing from. |
-r |
Reverse the order of the pages. |
-t format |
Specify paper size and format; valid options include `letter', `legal', `a4', and `landscape'. (You can use this option twice, say to specify both `legal' and `landscape'). |
$ dvips -m -t landscape envelope.dvi [RET]
lpr
using the
`-d' option.
To print the contents of an xterm
window, press and hold
[CTRL] and left-click anywhere inside the window, and choose the
Print Window
option. This command will send a copy of all the
text in the current window to the default printer.
Not all printers recognize all output formats, so it's sometimes necessary to convert files before you print them.
Normally, you can print plain text on any printer. However, most graphics or image files must be converted to PostScript or EPS ("Encapsulated PostScript"). Some applications -- such as TeX---produce DVI output; in this case, you convert that to PostScript for printing.
If you have a PostScript printer, you can print PostScript files directly to it. If not, you'll need to convert the PostScript output to a format your printer uses. Filter programs like `magicfilter' make the conversion easier by doing this work for you, but they're not a panacea, since your system may use one of a great many filters. Hence, the need for the following recipes.
Debian: `gs' WWW: ftp://www.gnu.org/pub/gnu/ghostscript/
If you don't have a PostScript printer, you can use Ghostscript,
gs
, to convert PostScript to an output format that your printer
understands.
Use the `-?' option to list the printers that the version of
gs
installed on your system can write output for.
$ gs -? [RET] GNU Ghostscript 5.10 (1998-12-17) ...more output messages... Input formats: PostScript PostScriptLevel1 PostScriptLevel2 PDF Available devices: x11 x11alpha x11cmyk x11gray2 x11mono lvga256 vgalib t4693d8 tek4696 appledmp ccr lp2563 lbp8 lips3 m8510 oki182 okiibm la50 la70 la75 la75plus sxlcrt deskjet djet500 laserjet ljetplus ljet2p ljet3 ljet4 declj250 cdeskjet cdjcolor cdjmono cdj550 cdj500 djet500c hpdj uniprint epson eps9mid eps9high epsonc lq850 ap3250 ibmpro bj10e bj200 bjc600 bjc800 ljet3d faxg3 faxg32d faxg4 dfaxhigh dfaxlow pcxmono pcxgray pbm pbmraw pgm pgmraw pgnm pgnmraw pnm pnmraw ppm ppmraw pkm pkmraw tiffcrle tiffg3 tiffg32d tiffg4 psmono psgray jpeg ...more output messages... $
A typical gs
installation can write to more than 100 different
print devices, including HP LaserJet 4 printers (`ljet4'), HP Color
DeskJets (`cdeskjet'), and Group 4 fax (`tiffg4'). Newer
versions of gs
will have better support for newer printers, so
make sure that you have a recent version installed if you have a new
model printer.
gs
takes the file to convert as an argument; give the device to
write output for as an argument to the `-sDEVICE=' option, and give
the name of the file to write to as an argument to the
`-sOutputFile=' option.
Two additional options are commonly used: `-dSAFER', which prevents the accidental deleting or overwriting of files, and `-dNOPAUSE', which turns off the pause between pages.
When the conversion is complete, you will be at the gs
prompt;
type quit to exit.
$ gs -sDEVICE=cdj500 -sOutputFile=tiger.dj -dSAFER -dNOPAUSE tiger.ps < /dev/null [RET]
This command writes the output to a file, `tiger.dj', which you can
spool as a print job with lpr
to print.
Debian: `tetex-bin' WWW: http://www.radicaleye.com/dvips/
To convert a file from DVI format to PostScript, use dvips
. It
takes the file to convert as an argument; give the name of the
PostScript file to write to as an argument to the `-o' option.
$ dvips -o abstract.ps abstract.dvi [RET]
This command reads the DVI file `abstract.dvi' and writes a PostScript version of it to the file `abstract.ps'; the original file is not altered.
To write only certain pages of a DVI file to the PostScript output, give the page or pages as arguments to the `-pp' option.
$ dvips -pp14,36 -o abstract.ps abstract.dvi [RET]
$ dvips -pp2-100 -o abstract.ps abstract.dvi [RET]
$ dvips -pp1,5-20 -o abstract.ps abstract.dvi [RET]
To specify an output paper size, give it as an argument to the `-t' option; if you have a PostScript printer, you can also send the output directly to the printer (see Printing with Dvips).
$ dvips -t legal -o abstract.ps abstract.dvi [RET]
$ dvips -t landscape abstract.dvi [RET]
NOTE: This conversion is not only useful for print preparation. Once the DVI file is converted to PostScript, you can then convert the PostScript to other formats, such as plain text or PDF -- see Converting PostScript.
Use the `-P' option with dvips
to specify the printer name
to write output to -- use this option to make output for non-PostScript
printers. For example, to convert TeX and LaTeX files to PDF, use
dvips
and give `pdf' as an argument to the `-P' option.
$ dvips -Ppdf -o abstract.pdf abstract.dvi [RET]
This command writes a new file, `abstract.pdf', in PDF format.
Debian: `xpdf' Debian: `gs' WWW: http://www.aimnet.com/~derekn/xpdf/ WWW: http://www.cs.wisc.edu/~ghost/
There are at least two ways to convert and print a file that's in
Adobe's Portable Document Format (PDF), usually marked with a
`.pdf' file name extension.
The first way is to view the file in xpdf
(the PDF file viewer),
and then left-click the printer icon. This won't actually send the file
to the printer, but it writes a PostScript file in the same directory,
with the same base file name as the PDF file but with a `.ps'
extension. You can then print this file with lpr
or convert it to
another format (see Preparing a PostScript File for Printing).
The second way is to use pdf2ps
, part of the `gs' package,
to convert the PDF file to PostScript (then print the PostScript output
as described for xpdf
above). pdf2ps
takes two arguments:
the name of the PDF file to convert, and the name of the PostScript file
to write to.
$ pdf2ps pricelist.pdf pricelist.ps [RET]
This command writes a PostScript file `pricelist.ps' in the current directory.
To convert a man
page to output that is suitable for printing,
use the `-t' to output PostScript, and either pipe the output to
lpr
(if you have a PostScript printer), or save it to a file that
you can then convert for your printer.
man
page for psbook
as PostScript and send
it as a print job to the default printer, type:
$ man -t psbook | lpr [RET]
man
page for psbook
to the file
`psbook.ps', type:
$ man -t psbook > psbook.ps [RET]
In the preceding example, you can then use gs
to convert the file
to a format your non-PostScript printer understands (see Preparing a PostScript File for Printing).
NOTE: A manual "page" can actually contain more than one physical page; the output will have as many pages as necessary to print it.
[<--] [Cover] [Table of Contents] [Concept Index] [Program Index] [-->]