Printing/zh

本文档介绍了如何利用CUPS和Samba进行打印机的安装和维护. 本文档包含本地打印机和网络打印进的安装以及如何使用网络上其他操作系统的共享打印机等. 有关使用 或者  命令打印文档的更多信息，详见 CUPS' excellent upstream documentation.

使用恰当的工具
Linux能够很好的支持各类打印机; CUPS (Common Unix Printing System)是linux下一个很优秀的打印作业服务. 自1999年项目建立以来，有关CUPS的安装和维护已经有了相当大的提高和改进.

这篇文当将介绍如何使用CUPS安装和配置本地打印机和网络打印机. 本文档只介绍一些简单的安装和配置信息. 需要更详细的信息请参阅 great documentation.

内核
当用户希望在系统上安装打印机时，第一步应该知道打印机是如何连接到系统上的. 与系统是通过本地端口LPT还是USB，亦或是通过网络？ 如果是网络连接的，那么它是使用Internet打印协议(IPP)还是使用Microsoft Windows CIFS协议(Microsoft Windows共享)？

接下来的几个部分将解释在Gentoo系统中使用打印机所需要的最少的内核配置. 当然, 这都是依据打印机是如何链接到系统上而分类的, 这里只是为了方便我们将说明分开几个部分介绍.

首先切换到目录 ，然后运行 来进入内核配置界面. 如果是使用 来配置的内核, 仍然要进行这些步骤以防止某些选项被遗漏. 不要寄希望于 genkernel 来自动的配置系统所有的选项; 打印这部分的配置是很难进行自动设置的.

下一个配置例子中，必要的支持会被设置为编译进内核而不是编译为模块，然后这样编译内核不是强制性的;如果你愿意可以编译为模块，但应记得要在需要的时候应加载这些模块.

现在，可以到你需要的部分去配置（检查）内核选项.

本地打印机 (LPT)
LPT端口通常用于识别并口打印机. 首先需要启用并口支持，然后是 PC样式并口支持 (除非你在使用 SPARC 系统)，这样你就启用了并口的支持.

That's it! 退出内核配置并且 重新编译内核.

现在继续进行CUPS的安装.

本地打印机 (LPT)
当CUPS使用USB USE标记编译时，可以支持USB本地打印. 它使用libusb库来提供用户空间的USB支持.

某些旧版本的软件可能仍需要启用内核中USB打印机的支持. 如果内核中编译为模块，则该模块名称为:

然而,使用内核中的打印机支持被认为 已经过时. 仅在确定必要的时候使用.

远程打印机 (IPP 和 LPD)
为了能够通过Internet打印协议或Line Printer Daemon 协议连接到远程连接的打印机，内核需要启用网络支持. 如果已启用网络支持，继续下边的步骤.

远程打印机 (CIFS)
内核必须 支持 CIFS:

CIFS配置完成后，退出内核配置并重新编译内核. 不要忘记将新编译的内核拷贝到位置（在此之前如果需要的话记着挂载/boot分区）和更新内核引导，然后重启系统. 请注意上述“LPT打印机配置”步骤中的root权限下的命令，了解如何执行这些步骤.

现在继续进行CUPS安装过程中的下一步.

USE 标志
CUPS还有一些可选功能. 要启用或禁用这些功能，请使用与它们关联的USE标志.

检查当前的USE标志设置. 如若单独为CUPS设置，请将这些USE标志添加到文件.

安装
如果确认无误，使用Portage来安装CUPS.

额外的软件
要启用SAMBA支持， 需要安装给CUPS提供支持. 更新 文件或者目录来启用 USE标志.

然后（重新）安装Samba:

打印组
需要使用打印机的用户应被添加到 用户组:

为了能够添加打印机并通过CUPS的Web界面进行编辑，任何允许编辑这些设置的系统用户都应该位于lpadmin组中：

OpenRC
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.

systemd
To start the CUPS daemon immediately and to make it start when the system boots, issue:

HTTP interface
Once the service is started, printers can be added by authenticated users. root is available by default and any member of the lpadmin group. Open up the following URL in a web browser:

http://localhost:631/

Files
The default CUPS server configuration located in 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 file. To share the printer using SAMBA, this change is not needed.

Open up in a favorite text editor and add in an   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.

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

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:

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 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:

Do not forget to restart the CUPS daemon after making changes to by issuing the  command.

Enable support for Windows PCL drivers
PCL drivers send raw data to the print server. To enable raw printing on CUPS, edit and uncomment the   line if it is not already uncommented. Then edit and do the same, if it is not already uncommented.

Do not forget to restart the CUPS daemon after making these changes by running.

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 file.

Assuming the printer is attached to a system called, open up  with a favorite text editor and set the   directive:

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

First list the available printers:

Set the HP LaserJet 5P as the default 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.

For a USB printer:

lpinfo
To list all available drivers, execute the following command:

is not chatty and can be a little tricky to use. If any issue arises, see for more information.

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.

Go to and enter the root login and password information of the box. Then, when the administrative interface has been reached, click on. 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.
 * 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, 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.

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


 * An LPD printer server requires a  syntax.
 * An HP JetDirect printer requires a  syntax.
 * An IPP printer requires a  or   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 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.

If the printer does not seem to work correctly, click on 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 In the next example a permission error is discovered, probably due to a wrong  setting in the  file.

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  driver.

Download the PPD file from the site and place it in then run  as root. This will make the driver available through the CUPS web interface. Now reconfigure the printer as described above.

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 to install them. Note the ebuild requests to quite a few USE flags. At minimum  and   must enabled for gutenprint drivers to work properly.

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 filter will need to be installed on the system:

Once installed, download the PPD file for the printer OpenPrinting and put it in the 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 package allows for quick portage-managed installation of these drivers. To install, run:

and restart.

Brother printer drivers
See Brother networked printer.

Canon CAPT driver
See Canon CAPT Driver.

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 wizard and select. When asked for the URI, use the  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 with a favorite text editor and add a   section to it:

Navigate to the top of the file until inside the   section. Locate the  and   settings and set each of them to   (see the example below):

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 has been emerged with the   USE flag enabled (as instructed above).

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

In the CUPS web interface, configure the printer as previously described. Notice CUPS has added another driver called. Select it and use the  or   syntax for the URI.

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, the 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.

Install via:

Printer configuration tool for KDE 4
KDE 4 also has a printer config tool called. It works with CUPS and provides a user-friendly interface to configure printers. Install it as follows:

USE flags
Packages that are currently installed with the  USE flag must be modified. Search through to see if any packages explicitly have the   flag and remove it.

Next, it may be necessary to remove the  value from 's USE variable if it had been previously set.

Unmerge
Finally, clean the system of any packages that are no longer needed as a result of CUPS being removed.

Error: Unable to convert file 0 to printable format
While having printing troubles and shows this message:

Re-emerge with the   USE flag. You can either add  to the system USE flags in  or enable it only for ghostscript-gpl as shown:

Then run. When it has finished compiling, be sure to restart afterward.

When using OpenRC:

When using systemd:

External resources

 * Using Network Printers - Documentation at CUPS.org.
 * Command-Line Printing and Options - Documentation at CUPS.org.