# Printers and printing

In this chapter we will learn more about printers and printing files. After reading this part, you will be able to:

- Format documents

- Preview documents before sending them to the printer

- Choose a good printer that works with your Linux system

- Print files and check on printer status

- Troubleshoot printing problems

- Find necessary documentation to install a printer

## Printing files

### Command line printing

#### Getting the file to the printer

Printing from within an application is very easy, selecting the Print option from the menu.

From the command line, use the `lp` or `lpr` command.

printing lp/lpr
lp
lpr
`lp `file(s)`` `lpr `file(s)``

These commands can read from a pipe, so you can print the output of commands using

I/O redirection printing
`command | lp`

There are many options available to tune the page layout, the number of copies, the printer that you want to print to if you have more than one available, paper size, one-side or double-sided printing if your printer supports this feature, margins and so on. Read the man pages for a complete overview.

#### Status of your print jobs

Once the file is accepted in the print queue, an identification number for the print job is assigned:

printing status

    davy:~> lp /etc/profile
    request id is blob-253 (1 file(s))

To view (query) the print queue, use the `lpq` or `lpstat` command. When entered without arguments, it displays the contents of the default print queue.

lpq
lpstat

    davy:~> lpq
    blob is ready and printing
    Rank	Owner	Job	File(s)		Total Size
    active	davy	253	profile		1024 bytes
    davy:~> lpstat
    blob-253	davy	1024	Tue 25 Jul 2006 10:20_01 AM CEST

#### Status of your printer

Which is the default printer on a system that has access to multiple printers?

printing status
`lpstat `-d``

    davy:~> lpstat -d
    system default destination: blob

What is the status of my printer(s)?

`lpstat `-p``

    davy:~> lpstat -p
    printer blob now printing blob-253. enabled since Jan 01 18:01

#### Removing jobs from the print queue

If you don't like what you see from the status commands, use `lprm` or `cancel` to delete jobs.

printing remove jobs
lprm
cancel

    davy:~> lprm 253

In the graphical environment, you may see a popup window telling you that the job has been canceled.

In larger environments, `lpc` may be used to control multiple printers. See the Info or man pages on each command.

There are many GUI print tools used as a front-end to `lp`, and most graphical applications have a print function that uses `lp`. See the built-in Help functions and program specific documentation for more.

Why are there two commands for every task related to printing?

Printing on UNIX and alikes has a long history. There used to be two rather different approaches: the BSD-style printing and the SystemV-style printing. For compatibility, Linux with CUPS supports the commands from both styles. Also note that `lp` does not behave exactly like `lpr`, `lpq` has somewhat different options than `lpstat` and `lprm` is almost, but not quite, like `cancel`. Which one you use is not important, just pick the commands that you are comfortable with, or that you may know from previous experiences with UNIX-like systems.

### Formatting

#### Tools and languages

If we want to get something sensible out of the printer, files should be formatted first. Apart from an abundance of formatting software, Linux comes with the basic UNIX formatting tools and languages.

Modern Linux systems support direct printing, without any formatting by the user, of a range of file types: text, PDF, PostScript and several image formats like PNG, JPEG, BMP and GIF.

For those file formats that do need formatting, Linux comes with a lot of formatting tools, such as the `pdf2ps`, `fax2ps` and `a2ps` commands, that convert other formats to PostScript. These commands can create files that can then be used on other systems that don't have all the conversion tools installed.

printing formatting tools

Apart from these command line tools there are a lot of graphical word processing programs. Several complete office suites are available, many are free. These do the formatting automatically upon submission of a print job. Just to name a few: OpenOffice.org, KOffice, AbiWord, WordPerfect, etc.

The following are common languages in a printing context:

printing languages overview

- `groff`: GNU version of the UNIX `roff` command. It is a front-end to the groff document formatting system. Normally it runs the `troff` command and a post-processor appropriate for the selected device. It allows generation of PostScript files.

  groff

- TeX and the macro package LaTeX: one of the most widely used markup languages on UNIX systems. Usually invoked as `tex`, it formats files and outputs a corresponding device-independent representation of the typeset document.

  TeX

  Technical works are still frequently written in LaTeX because of its support for mathematic formulas, although efforts are being made at W3C (the World Wide Web Consortium) to include this feature in other applications.

- SGML and XML: Free parsers are available for UNIX and Linux. XML is the next generation SGML, it forms the basis for DocBook XML, a document system (this book is written in XML, for instance).

  SGML
  XML

Printing documentation

The man pages contain pre-formatted `troff` data which has to be formatted before it can roll out of your printer. Printing is done using the `-t` option to the `man` command:

man pages printing
troff
printing man pages
`man `-t` command > `man-command.ps``

Then print the PostScript file. If a default print destination is configured for your system/account, you can just issue the command `man `-t` command` to send the formatted page to the printer directly.

#### Previewing formatted files

Anything that you can send to the printer can normally be sent to the screen as well. Depending on the file format, you can use one of these commands:

printing preview

- PostScript files: with the `gv` (GhostView) command.

  gv

- TeX dvi files: with `xdvi`, or with KDE's `kdvi`.

  xdvi
  kdvi

- PDF files: `xpdf`, `kpdf`, `gpdf` or Adobe's viewer, `acroread`, which is also available for free but is not free software. Adobe's reader supports PDF 1.6, the others only support PDF versions up to 1.5. The version of a PDF file can be determined using the `file` command.

  xpdf
  kpdf
  gpdf
  acroread

- From within applications, such as Firefox or OpenOffice, you can usually select Print Preview from one of the menus.

## The server side

### General

Until a couple of years ago, the choice for Linux users was simple: everyone ran the same old LPD from BSD's Net-2 code. Then LPRng became more popular, but nowadays most modern Linux distributions use CUPS, the Common UNIX Printing System. CUPS is an implementation of the Internet Printing Protocol (IPP), an HTTP-like RFC standard replacement protocol for the venerable (and clunky) LPD protocol. CUPS is distributed under the GNU Public License. CUPS is also the default print system on MacOS X.

printing CUPS
CUPS

### Graphical printer configuration

Most distributions come with a GUI for configuring networked and local (parallel port or USB) printers. They let you choose the printer type from a list and allow easy testing. You don't have to bother about syntax and location of configuration files. Check your system documentation before you attempt installing your printer.

printers printer configuration

CUPS can also be configured using a web interface that runs on port 631 on your computer. To check if this feature is enabled, try browsing to or .

### Buying a printer for Linux

As more and more printer vendors make drivers for CUPS available, CUPS will allow easy connection with almost any printer that you can plug into a serial, parallel, or USB port, plus any printer on the network. CUPS will ensure a uniform presentation to you and your applications of all different types of printers.

printers choosing

Printers that only come with a Win9x driver could be problematic if they have no other support. Check with when in doubt.

In the past, your best choice would have been a printer with native PostScript support in the firmware, since nearly all UNIX or Linux software producing printable output, produces it in PostScript, the publishing industry's printer control language of choice. PostScript printers are usually a bit more expensive, but it is a device-independent, open programming language and you're always 100% sure that they will work. These days, however, the importance of this rule of thumb is dwindling.

printers PostScript

## Print problems

In this section, we will discuss what you can do as a user when something goes wrong. We won't discuss any problems that have to do with the daemon-part of the printing service, as that is a task for system administrators.

### Wrong file

If you print the wrong file, the job may be canceled using the command `lprm jobID`, where jobID is in the form printername-printjobnumber (get it from information displayed by `lpq` or `lpstat`). This will work when other jobs are waiting to be printed in this printer's queue. However, you have to be really quick if you are the only one using this printer, since jobs are usually spooled and send to the printer in only seconds. Once they arrive on the printer, it is too late to remove jobs using Linux tools.

printing troubleshooting

What you can try in those cases, or in cases where the wrong print driver is configured and only rubbish comes out of the printer, is power off the printer. However, that might not be the best course of action, as you might cause paper jams and other irregularities.

### My print hasn't come out

Use the `lpq` command and see if you can spot your job:

    elly:~> lpq
    Printer: lp@blob
     Queue: 2 printable jobs
     Server: pid 29998 active
     Unspooler: pid 29999 active
     Status: waiting for subserver to exit at 09:43:20.699
     Rank   Owner/ID             Class Job Files          Size Time
    1      elly@blob+997           A   997 (STDIN)         129 09:42:54
    2      elly@blob+22            A    22 /etc/profile    917 09:43:20

Lots of printers have web interfaces these days, which can display status information by typing the printer's IP address in your web browser:

Printer Status through web interface

This GUI shows printer status using your browser. There is a trafic light indicating the status, and choices for managing the printer: view config, control panel, printer settings, online support and admin settings.

CUPS web interface versus printer web interface

Note that this is not the CUPS web interface and only works for printers supporting this feature. Check the documentation of your printer.

If your job ID is not there and not on the printer, contact your system administrator. If your job ID is listed in the output, check that the printer is currently printing. If so, just wait, your job will get done in due time.

If the printer is not printing, check that it has paper, check the physical connections to both electricity and data network. If that's okay, the printer may need restarting. Ask your system admin for advice.

In the case of a network printer, try printing from another host. If the printer is reachable from your own host (see for the `ping` utility), you may try to put the formatted file on it, like `file.ps` in case of a PostScript printer, using an FTP client. If that works, your print system is misconfigured. If it doesn't work, maybe the printer doesn't understand the format you are feeding it.

The GNU/Linux Printing site contains more tips and tricks.

## Summary

The Linux print service comes with a set of printing tools based on the standard UNIX LPD tools, whether it be the SystemV or BSD implementation. Below is a list of print-related commands.

New commands in chapter 8: Printing

Command | Meaning
--- | ---
`lpr` or `lp` | Print file
`lpq` or `lpstat` | Query print queue
`lprm` or `cancel` | Remove print job
`acroread` | PDF viewer
`groff` | Formatting tool
`gv` | PostScript viewer
`printconf` | Configure printers
`xdvi` | DVI viewer
`xpdf` | PDF viewer
`*2ps` | Convert file to PostScript

## Exercises

Configuring and testing printers involves being in the possession of one, and having access to the root account. If so, you may try:

- Installing the printer using the GUI on your system.

- Printing a test page using the GUI.

- Printing a test page using the `lp` command.

- Print from within an application, for example Mozilla or OpenOffice, by choosing File Print from the menu.

- Disconnect the printer from the network or the local machine/print-server. What happens when you try to print something?

The following exercises can be done without printer or root access.

- Try to make PostScript files from different source files, (e.g. HTML, PDF, man pages). Test the results with the `gv` viewer.

- Check that the print daemon is running.

- Print the files anyway. What happens?

- Make a PostScript file using Mozilla. Test it with `gv`.

- Convert it to PDF format. Test with `xpdf`.

- How would you go about printing a GIF file from the command line?

- Use `a2ps` to print the `/etc/profile` file to an output file. Test again with `gv`. What happens if you don't specify an output file?