[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

26. Printing

@sf{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 section 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 section Reading System Documentation and Help Files).

26.1 Making and Managing Print Jobs  Sending a job to the printer.
26.2 More Recipes for Printing  Print services in some applications.
26.3 Preparing Files for Printing  Converting files for your printer.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

26.1 Making and Managing Print Jobs

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.

26.1.1 Sending a Print Job to the Printer  Sending a print job.
26.1.2 Printing Multiple Copies of a Job  Printing more than one copy.
26.1.3 Listing Your Print Jobs  Listing your print jobs.
26.1.4 Cancelling a Print Job  Cancelling a print job.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

26.1.1 Sending a Print Job to the Printer

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.

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.")

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.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

26.1.2 Printing Multiple Copies of a Job

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.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

26.1.3 Listing Your Print Jobs

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.

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.

To only list the jobs for a particular user, give the name of the user as an argument.

NOTE: When there are no print jobs, lpq outputs the text `no entries'.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

26.1.4 Cancelling a Print Job

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.

To cancel all of your print jobs in the spool queue, use a hyphen instead of the number of a print job.

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).


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

26.2 More Recipes for Printing

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 section 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 section LyX Document Processing).

Some tools, such as dvips and enscript (see section 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.

26.2.1 Printing in Emacs  
26.2.2 Printing with Dvips  Printing with dvips.
26.2.3 Printing the Contents of an Xterm Window  Printing an xterm window.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

26.2.1 Printing in Emacs

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 section 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.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

26.2.2 Printing with Dvips

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.

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').

Using the `-m' option and specifying landscape as the paper format with the `-t' option is very useful for printing on envelopes.

NOTE: You can also print DVI files with lpr using the `-d' option.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

26.2.3 Printing the Contents of an Xterm Window

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.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

26.3 Preparing Files for Printing

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.

26.3.1 Preparing a PostScript File for Printing  Preparing PostScript for printing.
26.3.2 Preparing a DVI File for Printing  Preparing DVI for printing.
26.3.3 Preparing a PDF File for Printing  Preparing PDF for printing.
26.3.4 Preparing a Man Page for Printing  Preparing man pages for printing.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

26.3.1 Preparing a PostScript File for Printing

@sf{Debian}: `gs'
@sf{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.

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.

This command writes the output to a file, `tiger.dj', which you can spool as a print job with lpr to print.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

26.3.2 Preparing a DVI File for Printing

@sf{Debian}: `tetex-bin'
@sf{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.

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.

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 section Printing with Dvips).

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.

This command writes a new file, `abstract.pdf', in PDF format.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

26.3.3 Preparing a PDF File for Printing

@sf{Debian}: `xpdf'
@sf{Debian}: `gs'
@sf{WWW}: http://www.aimnet.com/~derekn/xpdf/
@sf{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 section 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.

This command writes a PostScript file `pricelist.ps' in the current directory.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

26.3.4 Preparing a Man Page for Printing

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.

In the preceding example, you can then use gs to convert the file to a format your non-PostScript printer understands (see section 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.


[ << ] [ >> ]           [Top] [Contents] [Index] [ ? ]

This document was generated using texi2html