Printing in Linux
Printing in Linux relies primarily on the CUPS (Common UNIX Printing System) print server. Most modern distributions (like Ubuntu or Fedora) include this out-of-the-box and will automatically detect connected or network printers, offering a seamless setup through your desktop's graphical printer settings.
CUPS (Common Unix Printer Service)
CUPS is a modular printer system for the UNIX-like operating systems that serves as a print server. But don’t think that a print server is a network-only system. The CUPS system can act as a printer server for a local machine or a network of machines. This means with one system you can set up printing for a local machine or for a group of networked machines.
CUPS consists of:
- Print spooler/scheduler: Lines up printing jobs to be sent to the printer.
- Filter system: Converts data so that the attached printer can understand and format the data being printed.
- Backend system: Transports data from filters to printer.
By default cups installs the following directories:
- /etc/cups: Configuration directory.
- /var/spool/cups/: The spooler directory where print jobs are held for printing.
- /var/spool/cups-pdf: The spooler directory where CUPS-generated PDF files are held for printing.
CUPS also installs an executable binary in /etc/init.d/ (or /etc/rc.d/init.d) called cups. This binary is started with the command:
/etc/init.d/cups start
Stopped with the command:
/etc/init.d/cups stop
And restarted with the command:
/etc/init.d/cups restart
Printer Setup
When you set up a printer in UNIX, the configuration creates a Postscript Printer Description file (ppd). This file contains all of the descriptions of a printers’ features as well as the PostScript code used to invoke features for a print job for that printer. This ppd file will be created no matter which setup tool you use. Most likely you will not have to touch this file. There¬† have been a few occasions where I have had to take care of a couple of very minor changes to this configuration file. Those are very rare instances however.
Now, let’s move on to the actual configuration.
In order to configure your printer with the CUPS web-based tool you need to open up your web browser and point it to http://localhost:631. What will appear is the main page for the CUPS web-based tool. The set up of a printer is simple. Here are the steps:
- Click the Add Printer button.
- Enter the name, location, and description of the printer.
- Select the device.
- Enter the device URI (this instructs the backends where the printer is located).
- Select the Manufacturer of your printer.
- Select the Model of your printer.
- Configure any general settings for your printer.
Printing Files
CUPS provides both the System V (lp) and Berkeley (lpr) commands for printing:
lp filename lpr filename
Both the lp and lpr commands support printing options for the driver:
lp -o media=A4 -o resolution=600dpi filename lpr -o media=A4 -o resolution=600dpi filename
CUPS recognizes many types of images files as well as PDF, PostScript, and text files, so you can print those files directly rather than through an application.
If you have an application that generates output specifically for your printer then you need to use the -o raw or -l options:
lp -o raw filename lpr -l filename
This will prevent the filters from misinterpreting your print file.