Printing

Certify and Increase Opportunity.
Be
Govt. Certified Linux Administrator

A printing system handles the tasks involved in getting a print job from an application (or the command line) through the appropriate filters and into a queue for a suitable printer and then getting it printed. When a printer fails, the printing system can redirect jobs to other, similar printers.

Here are the most common print options

  • Printer selection. The list of available printers. .
  • Page range. Use commas or hyphens to select specific pages or a range of pages. For example, typing 1, 4, 20-23 prints pages 1, 4, 20, 21, 22, and 23. The Selection option prints only the selected text or graphics in a document. Current Page prints only the currently displayed page.
  • Number of copies. Print more than one copy of a document, picture, or file. Select the Collate check box to print a document in its entirety before moving to the next copy.
  • Page orientation. Also called page layout. Choose between a tall page (Portrait) or wide page (Landscape).
  • Paper size. Select different size paper.
  • Output or paper source. Also called output destination or paper tray. Choose a paper tray to use—handy especially if you load each tray with different sizes of paper.
  • Double-sided printing. Also called duplex or two-sided printing. Choose this to print on both sides of a sheet.
  • Print color. Choose between black-and-white and color prints.

Traditionally, UNIX had two printing systems: the BSD Line Printer Daemon (LPD) and the System V Line Printer system (LPR). Linux adopted these systems at first, and both UNIX and Linux have seen modifications to and replacements for these systems. Today CUPS is the default printing system

CUPS (Common UNIX Printing System) is a cross-platform print server built around IPP (next). CUPS provides many printer drivers and can print different types of files, including PostScript. Because it is built on IPP and written to be portable, CUPS runs under many operating systems, including Linux and Windows. CUPS provides System V and BSD command-line interfaces and, in addition to IPP, supports LPD/LPR, HTTP, SMB, and JetDirect (socket) protocols, among others.

The IPP project (Internet Printing Protocol; www.pwg.org/ipp) began in 1996, when Novell and several other companies designed a protocol for printing over the Internet. IPP enables users to

  • Determine the capabilities of a printer.
  • Submit jobs to a printer.
  • Determine the status of a printer.
  • Determine the status of a print job.
  • Cancel a print job.

IPP is an HTTP-based client/server protocol in which the server side can be a print server or a network-capable stand-alone printer.

On a modern computing system, when you “send a job to the printer,” you actually add the job to the list of jobs waiting their turn to be printed on a printer. This list is called a printqueue or simply a queue. The phrase configuring (or setting up) a printer is often used to mean configuring a (print) queue. This chapter uses these phrases interchangeably.

In most cases, when you connect a printer to the local system and turn it on, Linux asks twice if you want to install drivers. When the drivers are installed, the printer is ready for use.

CUPS

CUPS manages print jobs and queues and provides network printing using the standard Internet Printing Protocol (IPP), while offering support for a very large range of printers, from dot-matrix to laser and many in between. CUPS also supports PostScript Printer Description (PPD) and auto-detection of network printers, and features a simple web-based configuration and administration tool.

The CUPS server configuration located in /etc/cups/cupsd.conf. After editing, restart org.cups.cupsd.service to apply any changes. The default configuration is sufficient for most users. Groups with printer administration privileges are defined in SystemGroup in the /etc/cups/cups-files.conf. The sys group is used by default.

CUPS is based around the Internet Printing Protocol standard (IPP), which is an IETF protocol derived from HTTP. The CUPS daemon understands IPP requests and it is the primary means of communication with its client applications. As an Internet protocol, IPP makes it easy to deploy print servers on wide-area networks. CUPS also supports other popular protocols used to communicate with printers, and thus can be used to act as a bridge for networked printers that don’t have native IPP support. Just like HTTP on which it is based, IPP can be secured by using authentication and SSL connections. CUPS provides native support for this, allowing for secure printing.

Another standard that CUPS embraces is the PostScript Printer Definition file format (PPD), which is another Adobe standard used to describe the capabilities of Postscript printers. CUPS extends their usage to non-Postscript printers, making it one of the cornerstones of modular drivers in this architecture.

CUPS also uses many filters as a means of translating and transporting data to the printers. However, unlike BSD-like print spoolers, this is done in a much more intelligent way. There are different classes of filters available for CUPS.

  • Back-end filters provide the endpoint where the final data will be delivered. There are filters for parallel ports, TCP/IP socket connections, LPD, and other endpoints.
  • Document conversion filters ship in standard with CUPS, and are available to convert images, ASCII text, PDF files and HP-GL/2 vector documents to Postscript.
  • Interface or raster filters are referred to from the PPDs and are called to convert the documents from Postscript to an intermediary file format.

Printer classes are also implemented by CUPS. Originally a feature implemented by some System V printing systems, printers can be grouped into ‘classes’, to implement automatic load balancing. A class can be sent jobs to just like a regular queue. A job submitted to a class will be dispatched to the first available printer in that class.

Using a broadcasting protocol, all CUPS daemons on the same LAN communicate with each other, and queues configured on a server are automatically browsable and made available on other systems. CUPS also provides “implicit classes” for several printers that have the same name on different servers, providing automatic load balancing. CUPS also has support for SLP (Service Location Protocol), that some devices may implement to broadcast their presence.

On the client side, CUPS has both LPD-like and System V-like interfaces, meaning it provides both lpr, lpq… as well as lp, lpstat, et al. commands to the system. All of these commands are essentially IPP clients communicating with the CUPS daemon through IPP requests.

Additionally, CUPS comes with a Web-based administration interface to directly let administrators and users configure queues from a Web browser, or just check their status. This is generally a lot more user-friendly than using cryptic commands, or manually defining queues by editing the printers.conf file in /etc/cups.

Local printers – To have the printer installed on the system, fire up a browser and point it to http://localhost:631. The CUPS web interface should be displayed from which all administrative tasks can be performed. Go to Administration and enter the root login and password information your GNU/Linux system. Then, when the administrative interface has been reached, click on Add Printer. A new screen will be displayed allowing the following information to be entered:

  • The spooler name, a short but descriptive name used on the system to identify the printer. This name should not contain spaces or any special characters. For instance, for the HP LaserJet 5P could be titled hpljet5p.
  • The location, a description where the printer is physically located (for instance “bedroom”, or “in the kitchen right next to the dish washer”, etc.). This is to aid in maintaining several printers.
  • The description should contain a full description of the printer. A common use is the full printer name (like “HP LaserJet 5P”).

The next screen requests the device the printer listens to. The choice of several devices will be presented. The next table covers a few possible devices, but the list is not exhaustive.

Device Description
AppSocket/HP JetDirect This special device allows for network printers to be accessible through a HP JetDirect socket. Only specific printers include support for this option.
Internet Printing Protocol (IPP or HTTP) Used reach the remote printer through the IPP protocol either directly (IPP) or through HTTP.
LPD/LPR Host or Printer Select this option if the printer is remote and attached to a LPD/LPR server.
Parallel Port #1 Select when the printer is locally attached to a parallel port (LPT). When the printer is automatically detected its name will be appended to the device.
USB Printer #1 Select when the printer is locally attached to a USB port. The printer name should automatically be appended to the device name.

If installing a remote printer, the URL to the printer will be queried:

  • An LPD printer server requires a lpd://hostname/queue syntax.
  • An HP JetDirect printer requires a socket://hostname syntax.
  • An IPP printer requires a ipp://hostname/printers/printername or http://hostname:631/printers/printername syntax.

Next, select the printer manufacturer in the adjoining screen along with the model type and number in the subsequent screen. For many printers multiple drivers will be available. Select one now or search on OpenPrinting Printer List for a good driver. Drivers are easily able to be changed later.

Once the driver is selected, CUPS will inform that the printer has been added successfully to the system. Navigate to the printer management page on the administration interface and select Configure Printer to change the printer’s settings (resolution, page format, …).

To verify if the printer is working correctly, go to the printer administration page, select the printer and click on Print Test Page. If the printer does not seem to work correctly, click on Modify Printer to reconfigure the printer. The same screens as during the first installation will appear but the defaults will now be the current configuration.

If the printer does not function, clues may be found by looking at the CUPS error log located at /var/log/cups/error_log. In the next example a permission error is discovered, probably due to a wrong Allow setting in the /etc/cups/cupsd.conf file.

tail /var/log/cups/error_log

(…)

E [11/Jun/2005:10:23:28 +0200] [Job 102] Unable to get printer status (client-error-forbidden)!

Other directives used in the cupsd.conf file, are

  • Browsing This directive controls whether network printer browsing is enabled.
  • BrowseProtocols This specifies the protocols to use when collecting and dis-tributing shared printers on the local network.
  • BrowseInterval This specifies the maximum amount of time between brows-ing updates.
  • BrowseAddress This specifies an address to send browsing information to.
  • ServerName   This directive specifies the hostname that is reported to clients.
  • Location This specifies access control and authentication options for the speci-fied Hypertext Transfer Protocol (HTTP) resource or path. A particularly interesting location is the root location, represented by the slash symbol (/). This location in the default cupsd.conf file

Some possible device URIs for locally attached printer are specified as

  • parallel:/dev/lp* For a printer attached to the parallel port
  • serial:/dev/ttyS* For a printer attached to the serial port
  • usb:/dev/usb/lp* For a printer attached to the USB port

Remote Printers – Note: As of CUPS version 1.6, the client defaults to IPP 2.0. If the server uses CUPS <= 1.5 / IPP <= 1.1, the client does not downgrade the protocol automatically and thus cannot communicate with the server. A workaround (undocumented as of 2013-05-07, but see this bug report) is to put the following in /etc/cups/client.conf: ServerName HOSTNAME-OR-IP-ADDRESS[:PORT]/version=1.1

Remote print servers can be accessed by adding an IPP “printer” to the local CUPS server, with a URI of ipp://192.168.0.101:631/printers/<name-of-printer>

The server can be configured using either the web interface or by manually editing /etc/cups/cupsd.conf.

  • Using the web interface – Open up the web interface to the server, select the Administration tab, look under the Server heading, and enable the “Share printers connected to this system” option. Save your change by clicking on the Change Settings button. The server will automatically restart. For more complex configurations, you can directly edit the /etc/cups/cupsd.conf file by selecting Edit Configuration File.
  • Manual setup – On the server computer (the one directly connected to the printer), allow access to the server by modifying the location directive. For instance:

/etc/cups/cupsd.conf

<Location />

Order allow,deny

Allow localhost

Allow 192.168.0.*

</Location>

Also make sure the server is listening on the IP address the client will be addressing:

/etc/cups/cupsd.conf

Listen <hostname>:631

There are more configuration possibilities, including automatic methods, which are described in detail in Using Network Printers.

After making any modifications, restart CUPS.

LPD (network) –   LPD is the Line Printer Daemon. CUPS supports printers that are attached to systems running this daemon. Most UNIX/Linux systems (even some Windows servers) support this daemon. So if a printer is attached to a host that supports LPD, CUPS can be used to make that printer available on the network to other hosts that do not necessarily support LDP. Virtually all HP laser printers with network connectivity also natively support LPD. A sample device URI to address an LPD printer is lpd:// hostname /queue, where hostname is the name of the machine where LPD is running.

SMB (network) – SMB is the Service Message Block. This is the foundation of file and printer sharing on Windows networks. Linux/UNIX hosts also support SMB through the use of the Samba software. For example, if a Windows system (or a Samba server) has a printer shared on it, CUPS can be configured to access and make that printer available to its own clients. A sample device URI to address an SMB printer resource is smb:// servername /sharename, where sharename is the name by which the printer has been shared on the Windows box or on the Samba server.

Setting Linux Print Spooling

Printing is supported by “lpd” the line printer spooler daemon, which you should activate to support print services. Once print services are setup, type “lpr ?s -Pprinter filename” where “printer” is the name of your printer (the default is lp). The ‘-s’ option tells lpr to use symbolic links to print the file rather than copying it to its own spool file. If the ‘-P’ option is left out, the default printer name will be assumed.

Other useful commands for printing:

  • lpr – Prints a file to default lp printer
  • lpq – shows files to print in the print que
  • lpc – Line printer control program. Type “lpc status” to see status on all printers. This command can enable or disable printing or queuing.
  • lprm – Remove a job from the print queue using number reported by lpq. Ex: lprm 14
  • tunelp – A utility to optimize the printer. “tunelp /dev/lp -q” will display the IRQ for the device

The directory /var/spool/lpd contains a directory for every printer. This is where the print files are spooled.

The BSD LPD printing system

As its name implies, this print system spawned from the Berkeley distribution of UNIX. The Line Printer Daemon (LPD) is still the basis for many other printing systems and spoolers that borrowed its interface and configuration file format, the printcap files. While LPD was initially developed for use with line printers that could only print a line of text at a time, it can be used for full page printers as well.

This was the printing system that made it in the first complete Linux distributions, like the early versions of Slackware. Nowadays, many distributions still ship this print spooler (Debian, Slackware), often alongside other more modern print systems like the other ones discussed in this article. There are many variants of the original BSD spooler still in use today.

The BSD printing system is really just a spooler – that is, its core functionality is limited to queuing jobs. It consists of a daemon (lpd), a couple of configuration files in /etc where queues and their properties are defined, a spooling directory where pending jobs will be held (usually /var/spool/lpd), and a set of basic commands to submit, delete and manipulate jobs (lpq, lprm, lpc).

Queues are defined in the /etc/printcap file, which follows the same format as termcap files, used to describe the capabilities of UNIX terminals. A typical printer entry would look like this :

# Sample queue definition for BSD LPD

lp|printer1:

:sd=/var/spool/lpd/lp:

:lp=/dev/lp0:

:if=/usr/sbin/somefilter:

:mx#0:

:sh:

Each entry defines a queue. There can be several queues referring to the same physical printer (for instance to distinguish certain options). A queue can also have several aliases. In the example above, the queue lp has an alias ‘printer1’. Jobs can be sent to either of these printer names, and will be dropped in the same queue. As a side note, ‘lp’ is usually considered the default queue in the BSD world.

Jobs are submitted to the spooler via the lpr command. A specific queue can be specified with the -P argument. For instance :

lpr -Pprinter1 /path/to/some/file

Jobs that have been submitted but have not yet been processed can be removed from the queue, using the lprm command. The job ID number, as well as various status information, can be obtained by running the lpq command.

BSD LPR is significant because it also defined the LPD network protocol, which is used to submit jobs to remote LPD daemons, and allows UNIX workstations to function as print servers. This protocol is nowadays natively supported by virtually all networked printers. Because of its widespread usage, all other printing systems have had the requirement to at least be able to talk to other LPD daemons and thus implement this protocol.

Here is an example of how to define a remote queue in a printcap file. The jobs will be immediately transferred to the remote queue on the remote LPD daemon, and won’t be processed on the original host.

# Sample queue definition for a remote LPD queue on a client

remote:

:sd=/var/spool/lpd/remote:

:rm=printserver.domain.tld:

:rp=queue:

:mx#0:

The rm attribute indicates the address of the remote LPD server. The rp attribute is the name of the queue on this server where jobs will be sent.

The /etc/lpd.hosts file is used to define which hosts are allowed to forward jobs to the local LPD daemon.

The LPD protocol sends data in two different pieces. First, a control file describing the job will be constructed and sent. This control file includes information about the originating user, the name of the files, and any options attached to the job. Then, the data file follows – it is the document itself and its format is entirely dependent on the printing language in use at the time.

The LPRng printing system

While BSD provided the basis of Unix print spoolers, its functionality is limited. Several projects were started to improve on it and add better configurability and more flexibility. The most wide-spread BSD-based printing system on Linux nowadays is LPRng (LPR Next Generation), written by Patrick Powell. It is essentially a rewrite of the original BSD LPR system, but all of the previous concepts still apply.

While LPRng keeps the printcap file format, it introduces a number of new attributes that make its configuration much more flexible. Filter definitions can be separated and true I/O filters can be defined. Users can also define their own queues, by writing a .printcap file in their home directory.

LPRng also provides commands that emulate the UNIX System V-style printing commands (lp, lpstat, etc).

LPRng comes with the IFHP filter, which can be used with queues to automatically perform some data format conversions (for example to print ASCII text or images).

lp command

The lp is used to print files.

Syntax

lp -i request-ID [-c] [-m] [-p] [-s] [-w] [-d destination] [-f form-name] [-H special-handling] [-n number] [-o options] [-p pagenumbers] [-q priority-level] [-S character-set | print-wheel] [-t title] [-T content-Type [-r]] [-y mode-list]

lp submits files for printing, or alters a pending print job. Use a filename of “-” to specify printing from the standard input. lp uses the common printing system CUPS, providing many ways to set the default destination. The LPDEST and PRINTER environment variables are checked first. If neither are set, the current default set using the lpoptions command is used, followed by the default set using the lpadmin command.

Options Detail
Marks the end of options; use this to print a file whose name begins with a dash (-).
-E Forces encryption when connecting to the server.
-U username Specifies the username to use when connecting to the server.
-c This option is provided for backwards-compatibility only. On systems that support it, this option forces the print file to be copied to the spool directory before printing. In CUPS, print files are always sent to the scheduler via IPP which has the same effect.
-d destination Prints files to the destination printer.
-h hostname[:port] Chooses an alternate server.
-i job-id Specifies an existing job to modify.
-m Sends an email when the job is completed.
-n copies Sets the number of copies to print from 1 to 100.
-o “name=value [name=value …]” Sets one or more job options.
-q priority Sets the job priority from 1 (lowest) to 100 (highest). The default priority is 50.
-s Do not report the resulting job IDs (silent mode.)
-t “name” Sets the job name.
-H hh:mm

-H hold

-H immediate

-H restart

-H resume

Specifies when the job should be printed. A value of immediate will print the file immediately, a value of hold will hold the job indefinitely, and a UTC time value (HH:MM) will hold the job until the specified UTC (not local) time. Use a value of resume with the -i option to resume a held job. Use a value of restart with the -i option to restart a completed job.
-P page-list Specifies which pages to print in the document. The list can contain a list of numbers and ranges (#-#) separated by commas (e.g. 1,3-5,16). The page numbers refer to the output pages and not the document’s original pages – options like “number-up” can affect the numbering of the pages.

Common Job Options – Aside from the printer-specific options reported by the lpoptions command, the following generic options are available:

Job Options Detail
-o media=size Sets the page size to size. Most printers support at least the size names “a4”, “letter”, and “legal”.
-o landscape
-o orientation-requested=4 Prints the job in landscape orientation (rotated 90 degrees).
-o sides=one-sided
-o sides=two-sided-long-edge

-o sides=two-sided-short-edge

Prints on one or two sides of the paper. The value “two-sided-long-edge” is normally used when printing portrait (unrotated) pages, while “two-sided-short-edge” is used for landscape pages.
-o fit-to-page Scales the print file to fit on the page.
-o number-up=2
-o number-up=16 Prints multiple document pages on each output page.
-o cpi=N Sets the number of characters per inch to use when printing a text file. The default is 10.
-o lpi=N Sets the number of lines per inch to use when printing a text file. The default is 6.
-o page-bottom=N

-o page-left=N

-o page-right=N

-o page-top=N

Sets the page margins when printing text files. The values are in points – there are 72 points to the inch.

Examples

  • lp -d myprinter -o media=legal -o sides=two-sided-long-edge filename – Prints the double-sided legal document filename to printer myprinter.
  • lp -d myprinter -o scaling=200 filename – Print document filename across 4 pages.

lp -d myprinter -o cpi=12 -o lpi=8 -o page-left=72 filename – Print a text file with 12 characters per inch, 8 lines per inch, and a 1 inch left margin.

Back to Tutorial

Apply for Linux Administration Certification Now!!

http://www.vskills.in/certification/Certified-Linux-Administrator

Share this post
[social_warfare]
Samba and LDAP
DHCP

Get industry recognized certification – Contact us

keyboard_arrow_up