This is Gentoo's testing wiki. It is a non-operational environment and its textual content is outdated.

Please visit our production wiki at https://wiki.gentoo.org

打印

From Gentoo Wiki (test)
Jump to:navigation Jump to:search
This page is a translated version of the page Printing and the translation is 65% complete.
Resources

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

Printing and Gentoo Linux

使用恰当的工具

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

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

安装

内核

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

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

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

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

现在,可以到你需要的部分去配置(检查)内核选项。

本地打印机 (LPT)

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

KERNEL 并口打印机配置
'"`UNIQ--pre-00000001-QINU`"'
Note
部分用户可能需要启用Parallel port support中的部分选项。 可通过查看内核配置中 Help 说明获取更详细的信息

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

现在继续进行CUPS的安装.

本地打印机 (LPT)

当CUPS使用USB USE标记编译时,可以支持USB本地打印。它使用libusb库来提供用户空间的USB支持。

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

KERNEL USB Printer support
Symbol: USB_PRINTER [=n]
Type  :tristate
Prompt: USB Printer support
  Location:
    -> Device Drivers
      -> USB support (USB_SUPPORT [=y])
(1)     -> Support for Host-side USB (USB [=y])
  Defined at drivers/usb/class/Kconfig:21
  Depends on: USB_SUPPORT [=y] && USB [=y]

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

远程打印机 (IPP 和 LPD)

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

远程打印机 (CIFS)

内核必须 支持 CIFS:

KERNEL CIFS 打印机配置
'"`UNIQ--pre-00000006-QINU`"'

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

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

USE 标志

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

USE flags for net-print/cups The Common Unix Printing System

X Add support for X11
acl Add support for Access Control Lists
dbus Enable dbus support for anything that needs it (gpsd, gnomemeeting, etc)
debug Enable extra debug codepaths, like asserts and extra output. If you want to get meaningful backtraces see https://wiki.gentoo.org/wiki/Project:Quality_Assurance/Backtraces
kerberos Add kerberos support
openssl Use dev-libs/openssl instead of net-libs/gnutls for TLS support
pam Add support for PAM (Pluggable Authentication Modules) - DANGEROUS to arbitrarily flip
selinux  !!internal use only!! Security Enhanced Linux support, this must be set by the selinux profile or breakage will occur
ssl Add support for SSL/TLS connections (Secure Socket Layer / Transport Layer Security)
static-libs Build static versions of dynamic libraries as well
systemd Enable use of systemd-specific libraries and features like socket activation or session tracking
test Enable dependencies and/or preparations necessary to run tests (usually controlled by FEATURES=test but can be toggled independently)
usb Add USB support to applications that have optional USB support (e.g. cups)
xinetd Add support for the xinetd super-server
zeroconf Support for DNS Service Discovery (DNS-SD)

检查当前的USE标志设置。如若单独为CUPS设置,请将这些USE标志添加到/etc/portage/package.use文件。

root #emerge -pv net-print/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

安装

如果确认无误,使用Portage来安装CUPS。

root #emerge --ask net-print/cups

额外的软件

要启用SAMBA支持, 需要安装net-fs/samba给CUPS提供支持。更新/etc/portage/package.use 文件或者目录来启用cupsUSE标志。

FILE /etc/portage/package.use为samba启用cups USE标志
net-fs/samba cups

然后(重新)安装Samba:

root #emerge --ask net-fs/samba

配置

打印组

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

root #gpasswd -a username lp

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

root #gpasswd -a username lpadmin

服务

OpenRC

如果打印机是在本地连接到系统,并且每次启动后都需要使用打印机,那么CUPS守护程序就需要在启动时自动加载。在CUPS守护程序启动之前,请确保打印机已连接并已打开电源。

root #service cupsd start
root #rc-update add cupsd default

systemd

要使CUPS在系统启动时立即启动并开始工作,输入以下命令:

root #systemctl start cups.service
root #systemctl enable cups.service

HTTP 接口

服务启动后,经过身份验证的用户可以添加打印机。默认情况下root和lpadmin组的任何成员都添加。打开web浏览器输入以下URL:

localhost:631

配置文件

CUPS默认的配置文件位于/etc/cups/cupsd.conf,默认配置足以满足大多数用户的需求。然而,某些用户可能需要更改CUPS默认配置。

下一章节涵盖了一些经常需要的配置信息.

  • 允许其他系统使用连接到此Linux工作站的打印机。
  • 从远程系统授予对CUPS管理的访问权限。
  • 配置CUPS以支持Windows PCL驱动程序。建议Windows系统使用SAMBA共享打印机,因为大多数Windows驱动程序都是PCL驱动程序。
  • 将此系统配置为使用远程系统(不是Windows共享)的打印机。

远程打印机

对于通过IPP使用打印机的其他系统,必须在/etc/cups/cupsd.conf文件中明确授予对打印机的访问权限。要使用SAMBA共享打印机,不需要进行此更改。

在喜爱的文本编辑器中打开/etc/cups/cupsd.conf,并为应该能够访问打印机的系统添加Allow 行。在下一个示例中,localhost和IP地址以 192.168.0 开头的任何系统都被授予打印机访问权限。

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

此行向网络上的客户端广播浏览信息;它将让网络用户知道打印机何时可用:

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

另外,还需要指定端口CUPS侦听,以便它将响应来自网络上其他计算机的打印请求:

FILE /etc/cups/cupsd.confPort configuration
Listen *:631
#Listen localhost:631
Note
如果使用 CUPS 1.1 (现在已经过时), 远程打印的语法可能与下面有些差异:
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

如果需要远程管理,那么就需要对不仅限于localhost的系统授予对CUPS管理的远程访问权限。编辑/etc/cups/cupsd.conf文件,并明确的为每个需要访问权限的系统授予访问权限。例如,要授予对IP地址为192.168.0.3的系统的访问权限:

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

修改 /etc/cups/cupsd.conf 文件后,请记住使用 /etc/init.d/cupsd restart 命令重启CUPS守护程序:

启用 Windows PCL 驱动

PCL驱动程序将原始数据发送到打印服务器。要在CUPS上启用原始打印,请编辑/usr/share/cups/mime/mime.types并取消注释 application/octet-stream 行(如果尚未取消注释)。然后编辑/usr/share/cups/mime/mime.convs并执行相同操作(如果尚未取消注释)。

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

进行这些更改后,不要忘记使用/etc/init.d/cupsd restart重新启动CUPS守护程序

配置远程打印机

如果打印机已经被连接到远程的CUPS管理的服务器上,通过修改/etc/cups/client.conf文件可以很方便的配置和使用这些远程打印机.

假设打印机连接到名为 printserver.mydomain 的系统,请使用喜欢的文本编辑器打开 /etc/cups/client.conf 并设置 ServerName 指令:

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

远程系统会使用自己的一个默认打印机设置。要更改默认打印机,请使用lpoptions 命令。

首先,显示可用的打印机。

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

将HP LaserJet 5P设置为默认打印机:

root #lpoptions -d hpljet5p

配置打印机

说明

如果要配置的打印机通过其他打印服务器(运行CUPS)远程可用,则不需要以下说明。相反的,请阅读Setting up a Remote Printer.

检测打印机

如果在Linux系统启动时打开USB打印机或并行端口打印机,则可以从内核检索信息中看到成功检测到打印机。这仅仅是打印检测的指示而非要求。

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

对于USB打印机:

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

The lpinfo command can be used in order to list all connected printers:

root #lpinfo -v
network ipp
network http
network socket
network https
network ipps
network lpd
network lpd://BRW67890ABCDEF/BINARY_P1

Running lpinfo -l -v will give a more verbose output.


要列出所有可用的驱动,执行一下命令:

root #lpinfo -m

lpinfo 并不是很友好,还有可能有点棘手。如果出现问题,请参阅 man lpinfo 获取更多信息。

安装打印机

要在系统上安装打印机,请启动浏览器并将其指向-{R。打开CUPS Web界面,从中可以执行所有管理任务。

Note
如果在第一次访问界面时使用HTTPS连接与CUPS,则可能需要很长时间才能显示该页面。这是因为第一个请求触发了CUPS SSL证书的生成,这可能是一项耗时的工作。

转到 Administration 并输入框的root登录名和密码信息。然后,当到达管理界面时,单击 Add Printer 。将显示一个新屏幕,允许输入以下信息:

  • spooler name,系统上用于识别打印机的简短描述性名称。此名称不应包含空格或任何特殊字符。例如,对于HP LaserJet 5P,标题为 hpljet5p </ code>。
  • location,描述打印机的物理位置(例如“卧室”或“在洗碗机旁边的厨房中”等)。这有助于维护多台打印机。
  • description,打印机的完整描述。常见用途是完整的打印机名称(如“HP LaserJet 5P”)。

下一个屏幕请求打印机监听的设备。这里将介绍几种设备的选择。下表列出了一些可能的设备,但该列表并非详尽无遗。

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.

如果安装远程打印机,将查询打印机的URL:

  • LPD打印服务器地址是 lpd://hostname/queue
  • HP JetDirect打印机地址为socket://hostname
  • IPP 打印机地址为 ipp://hostname/printers/printername 或者 http://hostname:631/printers/printername

接下来,在随后的屏幕中选择相邻屏幕中的打印机制造商以及型号类型和编号。对于各种打印机,将提供不同的打印驱动程序。现在选择一个或在OpenPrinting Printer List上搜索一个好的驱动程序。驱动程序可以在以后轻松更改。

选择驱动程序后,CUPS将通知打印机已成功添加到系统中。导航到管理界面上的打印机管理页面,然后选择 Configure Printer来更改打印设置(分辨率、页面格式等等)。

测试与重新配置打印机

要验证打印机是否正常工作,请转到打印机管理页面,选择打印机并单击打印测试页

如果打印机不能正常工作,点击 修改打印机来重新配置打印机。与首次配置相同的界面会显示出来,显示的选项就是当前的配置。

如果打印机不能正常工作,可以从CUPS错误日志中查看信息。日志位于 /var/log/cups/error_log。下面的例子中显示出了权限错误,很可能是因为 /etc/cups/cupsd.conf文件中Allow行错误的配置。

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)!

安装合适的驱动程序

驱动程序很多,找出最适合的驱动,请访问 OpenPrinting Printer List。选择打印机品牌和型号类型来选择推荐的驱动。例如,对于打印机HP LaserJet 5P,推荐的驱动程序为ljet4驱动。

从网页下载PPD文件,并放置于/usr/share/cups/model中,然后在root权限下运行 /etc/init.d/cupsd restart。这将使这个驱动程序能在CUPS网页界面下可用。现在按照上边说明重新配置打印机。

使用专用的打印机驱动程序

说明

某些打印机需要专用的驱动程序或不能通过常规配置过程启用的额外的功能(如上所述)。本章将讨论一系列打印机以及它们如何与Gentoo Linux配合使用。

Gutenprint 驱动

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

root #emerge --ask net-print/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 net-print/splix

and restart cupsd.

Brother printer drivers

See Brother networked printer.

Canon CAPT driver

See Canon CAPT Driver.

Printing to and from Microsoft Windows

Note
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 net-fs/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 net-print/gtklp, 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:

root #emerge --ask net-print/gtklp

Printer configuration tool for KDE 4

KDE 4 also has a printer config tool called kde-apps/print-manager. It works with CUPS and provides a user-friendly interface to configure printers. Install it as follows:

root #emerge --ask kde-apps/print-manager

Removal

USE flags

Packages that are currently installed with the cups USE flag must be modified. Search through /etc/portage/package.use to see if any packages explicitly have the cups flag and remove it.

Next, it may be necessary to remove the cups value from /etc/portage/make.conf's USE variable if it had been previously set.

Unmerge

root #emerge --ask --depclean net-print/cups

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

root #emerge --ask --depclean

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.

When using OpenRC:

root #service cupsd restart

When using systemd:

root #systemctl restart cups

External resources


This page is based on a document formerly found on our main website gentoo.org.
The following people contributed to the original document: swift, nightmorph
They are listed here because wiki history does not allow for any external attribution. If you edit the wiki article, please do not add yourself here; your contributions are recorded on each article's associated history page.