This page is provided as a convenient way to download. It should also be helpful for people on dial-up to have one big page to read. A list of the other “AllOfs” can be found at http://linuxbasics.org/course/book/allallofs.
Please take into considerations that once you save this page, it cannot keep up with the dynamics of the wiki. If you find something to be corrected or improved, you need to check or edit the actual current wiki-page.
The current version of this document can be found at http://linuxbasics.org/course/book/index.
This book is licensed and may be distributed under the terms of the GNU Free Documentation License. A copy of the license can be found at http://linuxbasics.org/course/book/allof_appendix
Usually, these snapshots are updated daily between 05:00 and 05:15 UTC
This snapshot was created: Sun Jul 20 06:08:07 CEST 2008
In this chapter we will learn more about printers and printing files. After reading this part, you will be able to:
Prev: Exercises
Home
Next: Printing files
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.
lp file(s)
lpr file(s)
These commands can read from a pipe, so you can print the output of commands using
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.
Once the file is accepted in the print queue, an identification number for the print job is assigned:
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.
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
Which is the default printer on a system that has access to multiple printers?
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
If you don’t like what you see from the status commands, use lprm or cancel to delete jobs.
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.
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.
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, KOffice, AbiWord, WordPerfect, etc.
The following are common languages in a printing context:
-t option to the man command: 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. For printing Info pages, refer to the Info pages on info (you will need the source code of the command).
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:
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.
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.
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 localhost:631/help or localhost:631/.
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 that only come with a Win9x driver could be problematic if they have no other support. Check with the hardware compatibility HOWTO 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.
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.
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.
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.
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:
Figure 8-1. Printer Status through web interface
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 Chapter 10 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.
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.
Table 8-1. Printing related commands
| 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 |
Configuring and testing printers involves being in the possession of one, and having access to the root account. If so, you may try:
The following exercises can be done without printer or root access.
/etc/profile file to an output file. Test again with gv. What happens if you don’t specify an output file?
Copyright (c) by the authors.
This section of the wiki is licensed under the terms of the GNU Free Documentation License.
See the LBook-licensing page for details.
Linux® is a registered trademark of Linus Torvalds.