Printing

From Gentoo Wiki
Jump to: navigation, search
Other languages:
English • ‎español • ‎日本語 • ‎русский

This document covers the installation and maintenance of printers using CUPS and Samba. It covers local installation and networked installations and contains instructions on using shared printers from other operating systems.

Printing and Gentoo Linux

Use the Right Tools

Linux has great support for printers; the right tool for the job is called CUPS (Common Unix Printing System). Since the beginning of the project, back in 1999, the installation and maintenance of CUPS has improved dramatically.

In this document we will cover how to use CUPS to setup a local or networked printer. It will not go in too much detail since the project has great documentation available for advanced usage.

Configure your Kernel

Introduction

When a user desires to install a printer on a system the first step is knowing how the printer will be attached to the system. Is it through a local port like LPT or USB, or is it networked? If it is networked, does it use the Internet Printing Protocol (IPP) or the Microsoft Windows CIFS protocol (Microsoft Windows Sharing)?

The next few sections explain what minimal kernel configuration needed to get a printer connected in Gentoo. Of course, this depends on how the printer is going to be attached to the system, so for convenience the instructions have been separated.

Navigate to /usr/src/linux and run make menuconfig to enter the kernel configuration. If genkernel was used to configure the kernel, these steps should still be performed to make sure nothing was missed. Do not rely on genkernel to configure everything in the system automatically; printing is an area configuration settings are difficult to automatically set.

In the next configuration examples, the necessary support will be added into the kernel, not as modules. Building the kernel this way is not mandatory; if desired modular support can be easily added, just be sure to remember to load the appropriate modules!

Now go to the appropriate section to configure (or check) the kernel.

Locally Attached Printer (LPT)

The LPT port is generally used to identify the parallel printer port. You need to enable parallel port support first, then PC-style parallel port support (unless using a SPARC system) after which you enable parallel printer support.

KERNEL Parallel Port Printer Configuration
Device Drivers -->
  <*> Parallel port support
  <*> PC-style hardware
  [*] IEEE 1284 transfer modes
  Character Devices -->
    <*> Parallel printer support
Note
Some users might may to enable other options in the Parallel port support section. Check the kernel configuration Help function for more information.

That's it! Exit the kernel configuration and rebuild the kernel using the following command:

root #make && make modules_install

Do not forget to copy the newly compiled kernel image to the /boot location. If applicable mount /boot, and update the boot loader configuration prior to rebooting the system. For instance, when using GRUB2, these steps can be done by running the following commands:

root #mount /boot
root #make install
root #grub2-mkconfig -o /boot/grub.grub.cfg

Now continue with CUPS.

Locally Attached Printer (USB)

To print via USB, USB support must be enabled in the kernel:

KERNEL USB Port Printer Configuration
Device Drivers -->
  USB Support -->
    <*> Support for Host-side USB
    (...)
    --- USB Host Controller Drivers
    (Select the HCD that your system uses. If you do not know which one
     to select, run "lspci -v | grep HCI" from another terminal)
    <*> EHCI HCD (USB 2.0) support ( or )
    <*> OHCI HCD support           ( or )
    <*> UHCI HCD (most Intel and VIA) support

Exit the kernel configuration and rebuild the kernel. Do not forget to copy the new kernel image to the /boot location (if necessary mount the /boot partition before copying the kernel) and update the boot loader configuration prior to rebooting the system. Note the root commands listed in the LPT Printer Configuration step above for how to perform these steps.

Now continue with CUPS.

Remotely Attached Printer (IPP)

To be able to connect to a remotely attached printer through the Internet Printing Protocol the kernel needs to have networking support. Assuming the kernel has that already, continue with CUPS.

Remotely Attached Printer (CIFS)

The kernel must support CIFS:

KERNEL CIFS Printer Configuration
File systems -->
  Network File Systems -->
    <*> CIFS support (advanced network filesystem, SMBFS successor) 

After configuration for CIFS is complete, exit the kernel configuration and rebuild the kernel. Do not forget to copy the new kernel image to the /boot location (and don't forget to mount /boot if needed) and update the boot loader configuration prior to rebooting the system. Note the root commands in the LPT Printer Configuration step above for how to perform these steps.

Now continue with CUPS.

Installing and Configuring CUPS

Installation

Installing CUPS with Gentoo is a breeze. CUPS has a few optional features that might be of interest. To enable or disable those features, use the USE flags associated with them.


USE flag (what is that?) Default Recommended Description
X No Allows the user to use a desktop menu to load the CUPS configuration webpage into a preferred browser.
dbus No Adds support for the dbus system message bus.
pam No If print job authentication through the Pluggable Authentication Modules is needed, this will activate PAM support for CUPS.
ssl No If remote authentication and/or privacy is required support for the Secure Socket Layer must be enabled which will allow for encrypted printing sessions. Support for SSL must be available on all participating systems on the network.
usb No Support for working with printers connected via USB.

Check the current USE flag settings. To deviate from the current USE settings for CUPS alone, add the appropriate USE flags to /etc/portage/package.use file.

root #emerge -pv cups
[ebuild N     ] net-print/cups-1.7.3  USE="X acl dbus pam ssl threads usb -debug -gnutls -java -kerberos -lprng-compat -python (-selinux) -static-libs -systemd -xinetd -zeroconf" ABI_X86="(64) (-32) (-x32)" LINGUAS="ca es fr it ja pt_BR ru" PYTHON_SINGLE_TARGET="python2_7" PYTHON_TARGETS="python2_7" 0 kB

When happy with the result, have Portage install CUPS.

root #emerge --ask cups

To enable SAMBA support, net-fs/samba needs to be installed with CUPS support. Update the /etc/portage/package.use file or directory to enable the cups USE flag:

FILE /etc/portage/package.use Enabling cups USE flag for samba
net-fs/samba cups

Then (re)install Samba:

root #emerge --ask net-fs/samba
Important
Any user that needs to print should be added to the lp group:
root #gpasswd -a username lp

In order to be able to add printers and edit them via CUPS's web interface, any system user that is allowed to edit these settings should be in the lpadmin group:

root #gpasswd -a username lpadmin

If the printer is attached to the system locally, and the printer needs to be available every boot, the CUPS daemon will need to load automatically on start-up. Make sure the printer is attached and powered on before the CUPS daemon is started.

root #/etc/init.d/cupsd start
root #rc-update add cupsd default

Configuration

The default CUPS server configuration located in /etc/cups/cupsd.conf is sufficient for most users. However, some users might need to make changes to the CUPS configuration.

In the next section covers a few changes that are often needed:

  • Allow other systems to use the printer attached to this Linux workstation.
  • Grant access to the CUPS administration from remote systems.
  • Configure CUPS to support Windows PCL drivers. This is advised for Windows systems to be able to use a SAMBA-shared printer since most Windows drivers are PCL drivers.
  • Configure this system to use a printer attached to another system (not Windows share).

Remote Printer Access

For other systems to use the printer through IPP, explicit access to the printer must be granted in the /etc/cups/cupsd.conf file. To share the printer using SAMBA, this change is not needed.

Open up /etc/cups/cupsd.conf in a favorite text editor and add in an Allow line for the system(s) that should be able to reach to the printer. In the next example, access is granted to the printer from localhost and from any system whose IP address starts with 192.168.0.

FILE /etc/cups/cupsd.conf Allowing remote access to the printer
<Location />
  Order allow,deny
  Allow localhost
  Allow from 192.168.0.*
</Location>

This line broadcasts browsing information to the clients on the network; it will let network users know when the printer is available:

FILE /etc/cups/cupsd.conf Broadcast info
BrowseAddress 192.168.0.*:631

The port CUPS listens to will also need to be specified so that it will respond to printing requests from other machines on the network:

FILE /etc/cups/cupsd.conf Port configuration
Listen *:631
#Listen localhost:631
Note
If using CUPS 1.1 (which is now deprecated), a different syntax is required for remote printing requests:
CODE Deprecated CUPS 1.1 configuration
Port 631
(Make sure the next two lines are commented out)
#Listen 127.0.0.1:631
#Listen localhost:631

CUPS Remote Administration

If remote administration is needed, then access to the CUPS administration will need to be granted from more systems than the localhost. Edit the /etc/cups/cupsd.conf file and have explicit access granted to each system that requires access. For instance, to grant access to a system with an IP address of 192.168.0.3:

FILE /etc/cups/cupsd.conf Allowing remote access
pre>
<Location /admin>
(...)
  Encryption Required
  Order allow,deny
  Allow localhost
  Allow 192.168.0.3
</Location>
</pre>

Do not forget to restart the CUPS daemon after making changes to /etc/cups/cupsd.conf by issuing the /etc/init.d/cupsd restart command.

Enable Support for Windows PCL Drivers

PCL drivers send raw data to the print server. To enable raw printing on CUPS, edit /usr/share/cups/mime/mime.types and uncomment the application/octet-stream line if it is not already uncommented. Then edit /usr/share/cups/mime/mime.convs and do the same, if it is not already uncommented.

FILE /usr/share/cups/mime/mime.types Enable support for raw printing
application/octet-stream
FILE /usr/share/cups/mime/mime.convs
application/octet-stream     application/vnd.cups-raw    0    -

Do not forget to restart the CUPS daemon after making these changes by running /etc/init.d/cupsd restart.

Setting Up a Remote Printer

If the printers are attached to a remote CUPS-powered server the system can be easily configured to use the remote printer by modifying the /etc/cups/client.conf file.

Assuming the printer is attached to a system called printserver.mydomain, open up /etc/cups/client.conf with a favorite text editor and set the ServerName directive:

FILE /etc/cups/client.conf
# (Substitute printserver.mydomain with your print server name)
ServerName printserver.mydomain

The remote system will have a default printer setting which will be used. To change the default printer, use the lpoptions command.

First list the available printers:

root #lpstat -a
hpljet5p accepting requests since Jan 01 00:00
hpdjet510 accepting requests since Jan 01 00:00

Set the HP LaserJet 5P as the default printer:

root #lpoptions -d hpljet5p

Configuring a Printer

Introduction

If the printer to be configured is remotely available through a different print server (running CUPS) then the following instructions are not needed. Instead, read Setting Up a Remote Printer.

Detecting the Printer

If a USB printer or parallel port printer was powered on when the Linux system booted, it might be possible to retrieve information from the kernel stating successful detection of the printer. This is merely an indication of print detection and not a requirement.

user $dmesg | grep -i print
parport0: Printer, Hewlett-Packard HP LaserJet 2100 Series

For a USB printer:

user $lsusb
(...)
Bus 001 Device 007: ID 03f0:1004 Hewlett-Packard DeskJet 970c/970cse

Installing the Printer

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.


Note
If an HTTPS connection to CUPS is used the first time the interface is accessed it may take a very long time before the page appears. This is because the first request triggers the generation of CUPS SSL certificates which can be a time-consuming job.

Go to Administration and enter the root login and password information of the box. 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, ...).

Testing and Reconfiguring the Printer

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.

root #tail /var/log/cups/error_log
(...)
E [11/Jun/2005:10:23:28 +0200] [Job 102] Unable to get printer status (client-error-forbidden)!

Installing the Best Driver

Many printer drivers exist; to find out which one has the best performance the job, visit the OpenPrinting Printer List. Select the brand and type/model of the printer to find out what driver the site recommends. For instance, for the HP LaserJet 5P, the site recommends the ljet4 driver.

Download the PPD file from the site and place it in /usr/share/cups/model then run /etc/init.d/cupsd restart as root. This will make the driver available through the CUPS web interface. Now reconfigure the printer as described above.

Using Special Printer Drivers

Introduction

Some printers require specific drivers or provide additional features that are not enabled through the regular configuration process (described above). This chapter will discuss a selection of printers and how they are made to work with Gentoo Linux.

Gutenprint Driver

The gutenprint drivers are high-quality, open source printer drivers for various Canon, Epson, HP, Lexmark, Sony, Olympus and PCL printers supporting CUPS. They also support ghostscript, The Gimp, and other applications.

Gentoo's Portage tree contains an ebuild for the gutenprint drivers. Run emerge gutenprint to install them. Note the ebuild requests to quite a few USE flags. At minimum cups and ppds must enabled for gutenprint drivers to work properly.

root #emerge --ask gutenprint

When the emerge process has finished, the gutenprint drivers will be available through the CUPS web interface.

HPLIP Driver

See HPLIP Driver.

PNM2PPA Driver

PPA is an HP technology that focuses on sending low-level processing to the system instead of the printer which makes the printer cheaper but more resource consuming.

If the OpenPrinting site informs the pnm2ppa driver is the best option, then the pnm2ppa filter will need to be installed on the system:

root #emerge --ask pnm2ppa

Once installed, download the PPD file for the printer OpenPrinting and put it in the /usr/share/cups/model folder. Then configure the printer using the steps explained above.

SpliX Driver

SpliX is a set of CUPS printer drivers for SPL (Samsung Printer Language) printers. While SpliX drivers are available through OpenPrinting as well, the net-print/splix package allows for quick portage-managed installation of these drivers. To install, run:

root #emerge --ask splix

and restart cupsd.

Printing From and To Microsoft Windows

Note
You should read the Samba/CUPS Guide for more detailed information on setting up CUPS with Samba.

Configuring a Windows Client for IPP

Microsoft Windows supports IPP (Windows 9x and ME users need to install it separately). To install a printer on Windows that is attached to a Linux box, fire up the Add Printer wizard and select Network Printer. When asked for the URI, use the http://hostname:631/printers/queue syntax.

Configuring a Windows Client for a Samba Shared Printer

To share the printer on the CIFS network SAMBA must be installed and configured correctly. Doing this is beyond the scope of this article, however a quick configuration of SAMBA for shared printers will be covered.

Open /etc/samba/smb.conf with a favorite text editor and add a [printers] section to it:

CODE [printers] section
[printers]
  comment      = All printers
  path         = /var/spool/samba
  browseable   = no
  guest ok     = no
  writable     = no
  printable    = yes
  public       = yes
  printer name = hpljet5p

Navigate to the top of the smb.conf file until inside the [global] section. Locate the printcap name and printing settings and set each of them to cups (see the example below):

CODE Changing the [global] section of smb.conf
[global]
  (...)
  printcap name = cups
  printing      = cups

Make sure to enable windows pcl support in CUPS. Then, restart the smb service to have the changes take effect.

Configuring a Linux Client for a Windows Print Server

First make sure the printer is shared on Windows systems and that samba has been emerged with the cups USE flag enabled (as instructed above).

To find the desired printer's URI, run the following command, substituting server with the computer that is to probe for samba-shared printers:

user $smbclient -N '\\server\'

In the CUPS web interface, configure the printer as previously described. Notice CUPS has added another driver called Windows Printer via SAMBA. Select it and use the smb://username:password@workgroup/server/printername or smb://server/printername syntax for the URI.

Important
Any special characters in the above URI need to be appropriately quoted. For example:

smb://BEN-DESKTOP/HP Color LaserJet CP1510 series PCL6

becomes:

smb://BEN-DESKTOP/HP%20Color%20LaserJet%20CP1510%20series%20PCL6


This result string can be obtained by running the following command:

user $python2 -c 'import urllib; print "smb://" + urllib.quote("BEN-DESKTOP/HP Color LaserJet CP1510 series PCL6")'

Printing-related Applications

Introduction

Many tools exist to help configure a printer, use additional printing filters, add features to printing capabilities, etc. This chapter will list a few of them. Be aware the list is not exhaustive and not meant to discuss each tool in great detail.

Gtk-LP - A Gtk-powered Printer Configuration Tool

With Gtk-LP installation, modification and configuration of a printer can be performed from a stand-alone Gtk application. It uses CUPS and provides all standard CUPS capabilities. It is definitely worth checking out if the CUPS Web interface is disliked or if a stand-alone application for day-to-day printing routines is desired.

To install it, emerge gtklp:

root #emerge --ask gtklp

Troubleshooting

Error: Unable to convert file 0 to printable format

While having printing troubles and /var/log/cups/error_log shows this message:

CODE Error log
Unable to convert file 0 to printable format

Re-emerge app-text/ghostscript-gpl with the cups USE flag. You can either add cups to the system USE flags in /etc/portage/make.conf or enable it only for ghostscript-gpl as shown:

root #echo "app-text/ghostscript-gpl cups" >> /etc/portage/package.use

Then run emerge app-text/ghostscript-gpl. When it has finished compiling, be sure to restart cupsd afterward:

root #/etc/init.d/cupsd restart



This article is based on a document formerly found on our main website gentoo.org.
The following people have contributed to the original document: swift, nightmorph
They are listed here as the Wiki history does not provide for any attribution. If you edit the Wiki article, please do not add yourself here, your contributions are recorded on the history page.