This section covers material for topic 1.107.3 for the Junior Level Administration (LPIC-1) exam 102. The topic has a weight of 1.
In this section, learn how to:
- Add and remove jobs from configured printer queues
- Convert text files to PostScript for printing
You learned how to remove files from print queues in the previous section. Here you learn how to print files and change job options.
Many graphical programs provide a method of printing, usually under the File menu option. These programs provide graphical tools for choosing a printer, margin sizes, color or black-and-white printing, number of copies, selecting 2-up printing (which is 2 pages per sheet, often used for handouts), and so on. This section shows you the command-line tools for controlling such features, and then a graphical implementation for comparison.
The simplest way to print any file is to use the
lpr command and provide the file name. This
prints the file on the default printer. Listing 10 shows a simple
example plus a more complex example. The more complex command is explained below.
Listing 10. Printing with lpr
[ian@attic4 ~]$ echo abc>abc.txt [ian@attic4 ~]$ lpr abc.txt [ian@attic4 ~]$ lpr -Pxerox -J "Ian's text file" -#2 -m -p -q -r abc.txt [ian@attic4 ~]$ lpq -l xerox is ready ian: 1st [job 25 localhost] 2 copies of Ian's text file 1024 bytes [ian@attic4 ~]$ ls abc.txt ls: abc.txt: No such file or directory
Table 4 explains the options used on the more complex command above, along with other options that you may use with
|-C, -J, or -T||Set a job name.|
|-P||Select a particular printer.|
|-#||Specify number of copies. Note this is different to the -n
option you saw with the |
|-m||Send email upon job completion.|
|-l||The print file is already formatted for printing. Equivalent to
|-o||Set a job option.|
|-p||Format a text file with a shaded header. Equivalent to
|-q||Hold (or queue) the job for later printing.|
|-r||Remove the file after it has been spooled for printing.|
So, in our complex
lpr -Pxerox -J
"Ian's text file" -#2 -m -p -q -r abc.txt,
user ian is requesting a specific printer, giving a name to the job,
requesting 2 copies, requesting an email confirmation after printing,
holding the job, and having the file abc.txt removed after it has been
spooled. The subsequent commands show the held job and the fact that
the file has indeed been removed.
In addition to the
lpr command, the
lp command covered in the
previous section can also be used to print jobs, as well as modify
lpr also accept a file from stdin if
no file name is given on the command line. In contrast to
lpr, which quietly spools the job, the
lp default is to display the job number of
the spooled job as shown in Listing 11. Note that not all the
equivalent options on
lpr have the same name; for example,
Listing 11. Printing from stdin with lp
[ian@attic4 ~]$ lp abc request id is xerox-27 (1 file(s))
So we now have a held job in the xerox print queue. What to do? The
lp command has options to hold and release
jobs, using various values with the
option. Listing 12 shows how to release the held job. Check the
man page of
lp for information on other
Listing 12. Resuming printing of a held print job
[ian@attic4 ~]$ lp -i 25 -H resume
Many different printers are available today, but not all of them support
the same set of options. You can find out what general options are set
for a printer using the
-l option to display printer-specific options; Listing 13 shows an example. The man page for the
lp command also lists several common
options, particularly relating to portrait/landscape printing, page
dimensions, and placement of the output on the pages.
Listing 13. Checking printer options
[ian@attic4 ~]$ lpoptions -p xerox job-sheets=none,none printer-info='Xerox Docuprint C20' printer-is-accepting- jobs=1 printer-is-shared=1 printer-make-and-model='Xerox DocuPrint C20 Foomat ic/Postscript (recommended)' printer-state=3 printer-state-change-time=115550 6374 printer-state-reasons=none printer-type=143388 cpi=12 scp-fc5=true lpi=7 page-bottom=86 page-left=57 page-right=57 page-top=72 scaling=100 wrap=true [ian@attic4 ~]$ lpoptions -l PageSize/Page Size: *Letter A4 11x17 A3 A5 B5 Env10 EnvC5 EnvDL EnvISOB5 EnvM onarch Executive Legal PageRegion/PageRegion: Letter A4 11x17 A3 A5 B5 Env10 EnvC5 EnvDL EnvISOB5 En vMonarch Executive Legal Duplex/Double-Sided Printing: DuplexNoTumble DuplexTumble *None Resolution/Resolution: *default 150x150dpi 300x300dpi 600x600dpi PreFilter/GhostScript pre-filtering: EmbedFonts Level1 Level2 *No
So far, all our commands have been directed to the local CUPS server.
You can also direct most commands to the server on another system, by
-h option along with a port
number if it is not the CUPS default of 631.
Before moving on to filters, let's look at how all this magic
avails itself in a GUI application. Figure 2 shows the illustration
of Figure 1 in the GIMP, an image manipulation program. Using the
File > Print option, you have many choices about how to
print the image. In this application, you can also click the
Setup Printer button to choose a printer and see the
command that will be used to print the file, in this case,
lp -s -dxerox -oraw.
Figure 2. Printing from the GIMP
You may have noticed that we were able to print text files above, even though the r220 printer happens to be an Epson photo printer, while the xerox printer is a PostScript Xerox Docuprint C20. This magic feat is accomplished through the use of filters. Indeed, a popular filter for many years was named magicfilter.
The number of filters included with most CUPS packages allows almost any kind of file to be printed. Additional filters are available commercially, from companies including Easy Software Products, the developers of CUPS.
CUPS uses MIME (Multipurpose Internet Mail Extensions) types to
determine the appropriate conversion filter when printing a file.
The section on filter
installation, later in this tutorial, goes into detail.
Other printing packages may use the magic number
mechanism as used by the
file command. See
the man pages for
magic for more details.
The general print flow is to convert the input file to a PostScript format using the appropriate filter for the file type, such as texttops, imagetops, or pdftops. The PostScript format is then filtered through a pstoraster filter to create an intermediate raster format for non-PostScript printers before being filtered through a printer backend, which prepares it for printing on a particular printer. Ghostscript is a popular program that can print PostScript files on many different printers. A companion viewer allows display of the file on a monitor. Many printer backends are derived from Ghostscript printer drivers.
Before all of this was handled so automatically, it was necessary to
convert input to PostScript format. Images could be handled with a
program such as the GIMP that we saw earlier. ASCII text files were
usually converted to PostScript using the
a2ps command. The default for plain text
files is to print 2-up with a header and direct output to the default
printer as shown in Listing 14.
Listing 14. Printing text files with a2ps
[ian@attic4 ~]$ a2ps -4 abc.txt -o abc.ps [abc.txt (plain): 1 page on 1 sheet] [Total: 1 page on 1 sheet] saved into the file `abc.ps'
a2ps command can handle a wide range
of text file types and make intelligent decisions about the best way
to format them. For example, the default for LaTeX files is to first
format the file and then print 2-up. Listing 15 uses
a2ps to print a copy of the sample2e.tex
file that is distributed with LaTeX, and then shows a copy renamed to
sample2e.txt, and printed 4-up with headers. Both are saved to an
output PostScript format file. Figure 3 shows how the output of the
second command is formatted.
Listing 15. Saving output from a2ps as a PostScript file
[ian@attic4 ~]$ a2ps -4 -E -o fig3.ps sample2e.tex [sample2e.tex (tex, delegated to texi2dvi): 1 page on 1 sheet] [Total: 4 pages on 1 sheet] saved into the file `fig3.ps' [ian@attic4 ~]$ a2ps -4 -E -o fig3.ps sample2e.txt [sample2e.txt (plain): 4 pages on 1 sheet] [Total: 4 pages on 1 sheet] saved into the file `fig3.ps'
Figure 3. Pretty printed output from a2ps
There are many other filters that you can use to format files for printing in special ways. Most have a range of options. Check the man pages for more details. Some examples are:
- Formats test files for printing multiple pages on a single page.
- Performs similar functions for PostScript files as mpage does for text files.
- Rearranges the pages of a PostScript document for printing as a book or booklet, taking into account the number of pages per sheet and how the sheet is folded.