SDB:Print Settings with CUPS

跳转到:导航搜索

本文面向有经验的 Linux 用户。

It does not provide detailed explanations.

此处的一些细节可能略有陈旧(具体取决于 CUPS 版本),但总体而言,这些内容仍然有效。

This article describes CUPS up to version 2.x under Linux with the traditional filtering system and backends there.

如今的无驱动程序打印工作流程则大不相同。

症状

You are in charge of the administration of a CUPS printing system and find it very difficult to keep track of the different print queue settings. For example

  • Different users obtain different printouts (bad quality printouts or no printouts at all), even though they print identical data through the same queue.
  • In case of network printing, the printouts differ depending on the client machine used, although the user prints identical data through the same queue.
  • Different users have different default queue settings.
  • Different users have different default paper size settings or there are different default paper size settings in different application programs for the same user.
  • In case of network printing, different users use different CUPS servers.

原因

The cause is not a bug, but a basic feature of CUPS

  • All users can define their own different settings for each queue.
  • In addition, "root" can define different settings for every single machine (not only on client machines, but also on the CUPS server).

There is no such thing as "THE" default settings for a print queue.

解决方案

The solution is to know where the settings can be stored and which settings are applied in what situation.

Different default queue settings

There is no such thing as "THE" default print queue.

There is even no such thing as a system default print queue.

The usual system default queue is in /etc/cups/printers.conf stored as "DefaultPrinter queue_name" entry which is usually (but see below!) shown when root runs "lpstat -d". The usual system default queue can be set (as root) via "lpadmin -d queue_name".

Besides this any normal user can have his own default queue which is stored in ~/.cups/lpoptions (since CUPS 1.2 / openSUSE 10.2, it was ~/.lpoptions in CUPS 1.1) when the user runs "lpoptions -d queue_name" so that any user who runs "lpstat -d" could see his own different default queue.

Unfortunately also root can run "lpoptions -d queue_name" which stores a special kind of "semi system default queue" in /etc/cups/lpoptions which may cause confusion because now this queue is shown when root runs "lpstat -d" (and no longer the usual system default queue in /etc/cups/printers.conf). The "semi system default queue" is also used for normal users who do not have their own default queue setting.

Furthermore when a local cupsd is running and accepts CUPS browsing information from remote CUPS print servers about their remote queues, the local cupsd maintains the CUPS browsing information about remote queues in its remote.cache file (/var/cache/cups/remote.cache or /etc/cups/yes/remote.cache).

By default the "DefaultPrinter remote_queue_name" in the remote.cache file is what a remote CUPS server may broadcast as its default queue (but a CUPS server may not have a default queue setting) and this queue may be shown when root runs "lpstat -d" depending on whether or not there are additional system default queue settings at other places.

When several remote CUPS servers broadcast several default queues, it is basically undefined (i.e. an implementation detail of the current local cupsd) which remote default queue will become used as the local default queue (i.e. which queue is shown by the "lpstat -d" command).

It is possible to run as root on the local host the command "lpadmin -d remote_queue_name" and then the local cupsd will store this new kind of system default print queue in its remote.cache file.

Therefore there are three kind of system default print queues

  • A local queue in /etc/cups/printers.conf stored as "DefaultPrinter queue_name".
  • A queue in /etc/cups/lpoptions stored as "Default queue_name".
  • A remote queue in the remote.cache file stored as "DefaultPrinter queue_name".

But in the end the system default print queue setting does usually not really matter for the users because each user can set and maintain his own default queue so that for the users whatever system default print queue setting is usually irrelevant.

For the default queue setting, there is finally the environment variable "PRINTER". If this environment variable is set to a value other than "lp", this setting determines the default queue with highest priority. If "PRINTER" is set to "lp", it is ignored by CUPS. Reason: For traditional printing systems, there is often an entry in files like /etc/profile or /etc/SuSEconfig/profile which usually sets "PRINTER" to "lp". As this would determine the default queue with highest priority, it would be impossible to set any other default queue with the usual CUPS tools.

If there is no queue set to be the default queue, the first queue in alphabetical order is used by default.

Different default paper size settings

There is no such thing as "THE" default paper size.

There is even no such thing as a system default paper size.

When a print queue is set up, one of the available paper size choices in the PPD file (printer description file) for the particular printer is set as the default paper size for the print queue.

The usual default paper size for a print queue is stored in /etc/cups/ppd/<queue_name>.ppd in the "DefaultPageSize:..." entry. The usual default paper size can be set (as root) for example A4 via "lpadmin -p queue_name -o PageSize=A4" - provided the PPD file for that queue has an option called "PageSize" with a choice "A4", see "Command-line Tools" at SDB:CUPS in a Nutshell.

Usually the "DefaultPageSize" value is either "A4" or "Letter" but there are some printers for which neither "A4" nor "Letter" is an available paper size choice (e.g. small format photo printers) so that there is another default paper size.

It depends on the particular used printer setup tool which default paper size is set automatically when a print queue is set up.

Furthermore the cupsd (which actually writes the config files when a print queue is set up) sets the "DefaultPageSize" value in /etc/cups/ppd/<queue_name>.ppd according to cupsd's "locale" setting. Since CUPS version 1.4 this behaviour can be configured via the "DefaultPaperSize" directive in /etc/cups/cupsd.conf (see http://www.cups.org/documentation.php/doc-1.4/ref-cupsd-conf.html). A "locale" is a set of language and cultural rules, e.g. the usually used paper size in a particular region. Regarding "locale" see "man 7 locale" or have a look at http://en.wikipedia.org/wiki/Locale. The cupsd's locale is usually the locale that system processes run in. This could be different to the locale that the user's desktop and application programs run in. Therefore what a system default paper size should be could be different from the cupsd's point of view compared to the user's point of view.

To avoid unexpected results of the various automated default paper size settings it is recommended to specify the right default paper size (i.e. the size of the paper which is actually loaded in the printer's standard paper input tray) explicitly when a print queue is set up.

Besides this any normal user can have his own default paper size for each print queue stored in ~/.cups/lpoptions (since CUPS 1.2 / openSUSE 10.2, it was ~/.lpoptions in CUPS 1.1) and/or root might have set default paper sizes in /etc/cups/lpoptions for print queues.

Finally any application program and any printing dialog program may use its own default paper size either as hardcoded built-in value or as result of whatever algorithm in the particular program. For example it may depend on the locale setting of the user who runs the program (have a look at SDB:Plain Text versus Locale). It might even happen that an application program uses one default paper size to create a document but then a separated printing dialog program is called which uses another default paper size to print it.

Preferably application programs should query CUPS (more precisely a cupsd which is accessible on localhost or via network) to get the PPD file for a specific print queue and use the "DefaultPageSize" value as default paper size when the application is creating a document which is meant to be printed. Furthermore the application should use the matching "ImageableArea" values in the PPD to make sure that the content of the document does not exceed the actual printable area of the particular printer. Strictly speaking for an application which produces a document which is meant to be printed the page size is irrelevant. Actually only the printable area does matter when it comes to printing a document on a particular printer. Regarding "printable area" and "fit on paper" have a look at SDB:Landscape Printing.

Different CUPS server settings

By default the cupsd which is running on the local client machine is accessed.

But a single remote CUPS server could be specified on a client machine in /etc/cups/client.conf so that this one CUPS server is directly accessed, see the "Client-only configuration" section in the article SDB:CUPS in a Nutshell

Also any individual user can specify his CUPS server via the "CUPS_SERVER" environment variable or a "ServerName host.domain" entry in ~/.cupsrc or since CUPS 1.2 in ~/.cups/client.conf (compare http://www.cups.org/documentation.php/doc-1.2/ref-client-conf.html).

Have in mind that various application programs or destop tools may write to ~/.cupsrc or ~/.cups/client.conf via printing dialogs (e.g. the user may set a print server in his desktop system's printing dialogs).

Different printer specific settings

示例

For clarification purposes, we have chosen an example of a correct situation that becomes more and more confusing. To keep this example as concise and clear as possible, only command line instructions are used. However, it would make no difference if graphical tools like printer setup tools or printing dialogs in various application programs or the CUPS web frontend were used instead.

Initial state

The CUPS server is a machine named "sun" to which a color ink jet printer with the queues "mono" and "color" is attached.

Because both queues will be used for the same printer, the same PPD file is used as basis for the two queues, but with different default values preset for each queue.

The PPD files corresponding to the queues /etc/cups/ppd/mono.ppd and /etc/cups/ppd/color.ppd contain the following possible settings and default values

 *DefaultColors: Gray
 *Colors Gray ...
 *Colors Color ...
 ...
 *DefaultInkCartridge: Black
 *InkCartridge Black ...
 *InkCartridge Color ...
 ...
 *DefaultResolution: 600dpi
 *Resolution 150dpi ...
 *Resolution 300dpi ...
 *Resolution 600dpi ...
 

 *DefaultColors: Color
 *Colors Gray ...
 *Colors Color ...
 ...
 *DefaultInkCartridge: Color
 *InkCartridge Black ...
 *InkCartridge Color ...
 ...
 *DefaultResolution: 300dpi
 *Resolution 150dpi ...
 *Resolution 300dpi ...
 *Resolution 600dpi ...
 

In certain circumstances it makes sense to have several queues with their respective settings for the same printer due to the following reasons

It might be necessary to change several options when switching between print modes, especially in the case of color ink jet printers, as in the following example

  • For "mono" Colors=Gray and InkCartridge=Black
  • For "color" Colors=Color and InkCartridge=Color

Some particular print modes might only work with certain resolutions, especially in the case of color ink jet printers as in the following example

  • The resolutions 150dpi, 300dpi, and 600dpi work for "mono".
  • Only the resolutions 150dpi and 300dpi work for "color".

Since SuSE Linux 8.2 (exactly since Foomatic version 3.x) there is the "Printout Mode" option in most of the Foomatic PPD files for inkjet printers. When the user selects a printout mode then all the individual option settigs which are necessary for the particular printing mode are set simulaneously. Therefore one PPD file for one printer is sufficient in this case.

The machines "earth" and "moon" are CUPS clients without queues. In addition to "root", the normal users "tux" and "geeko" are on these machines, too.

除非队列已配置为其他设置,否则队列“mono”始终为所有机器生成 600 dpi 分辨率的灰度打印输出,而队列“color”始终为所有机器生成 300 dpi 分辨率的彩色打印输出。

现在将按照以下顺序更改选项

"root" 在 "sun" 上执行以下命令

lpadmin -p mono -o Resolution=150dpi

以将 PPD 文件 /etc/cups/ppd/mono.ppd 中的默认分辨率值更改为 150 dpi

 *DefaultColors: Gray
 *Colors Gray ...
 *Colors Color ...
 ...
 *DefaultInkCartridge: Black
 *InkCartridge Black
 *InkCartridge Color
 ...
 *DefaultResolution: 150dpi
 *Resolution 150dpi ...
 *Resolution 300dpi ...
 *Resolution 600dpi ...
 

因此,队列 "mono" 将以 150 dpi 分辨率的灰度方式为所有机器上的所有用户打印。

然后 "root" 在 "sun" 上执行以下命令

lpoptions -p mono -o Resolution=300dpi

以仅为机器 "sun" 在其文件 /etc/cups/lpoptions 中设置默认分辨率值为 300 dpi

 Dest mono Resolution=300dpi
 

因此,"mono" 将以 300 dpi 分辨率的灰度方式为 "sun" 上的所有用户打印,并以 150 dpi 分辨率的灰度方式为 "earth" 和 "moon" 上的所有用户打印。

现在 "root" 在 "earth" 上执行以下命令

lpoptions -p mono -o Resolution=600dpi

以仅为机器 "earth" 在其文件 /etc/cups/lpoptions 中设置默认分辨率值为 600 dpi

 Dest mono Resolution=600dpi
 

因此,"mono" 将以 600 dpi 分辨率的灰度方式为 "earth" 上的所有用户打印,以 300 dpi 分辨率的灰度方式为 "sun" 上的所有用户打印,并以 150 dpi 分辨率的灰度方式为 "moon" 上的所有用户打印。

普通用户 "tux" 在 "earth" 上执行以下命令

lpoptions -p mono -o Resolution=300dpi

以在主目录中的文件 ~/.cups/lpoptions (自 CUPS 1.2 / openSUSE 10.2 起,在 CUPS 1.1 中为 ~/.lpoptions) 中将他的默认分辨率值设置为 300dpi

 Dest mono Resolution=300dpi
 

因此,"mono" 将以 300 dpi 分辨率的灰度方式为 "earth" 上的用户 "tux" 打印,并以 600 dpi 分辨率的灰度方式为 "earth" 上的其余用户打印。 "sun" 和 "moon" 上的设置保持不变。

用户 "geeko" 在 "earth" 上执行以下命令

lpoptions -p mono -o Colors=Color

以更改他对队列 "mono" 的设置。用户 "geeko" 的新设置将保存在主目录中的文件 ~/.cups/lpoptions (或 ~/.lpoptions) 中

 Dest mono Colors=Color
 

Geeko 对队列 "mono" 的设置没有意义,因为使用了两个矛盾的值:Colors=Color 和 InkCartridge=Black。

"geeko" 在 "earth" 上执行以下命令

lpoptions -p color -o Resolution=600dpi

以将他对队列 "color" 的选项设置为如下。新的设置将保存在他的文件 ~/.cups/lpoptions (或 ~/.lpoptions) 中

 Dest color Resolution=600dpi
 Dest mono Colors=Color
 

队列 "color" 的 "geeko" 在 "earth" 上的设置是错误的,因为部署的值为 Resolution=600dpi,这对于此打印机不起作用(见上文)。这导致队列 "color" 对于 "geeko" 在 "earth" 上不再起作用。

"geeko" 在 "earth" 上执行以下命令

lpoptions -p color -o Resolution=1200dpi -o Foo=Bar

以将他对队列 "color" 的选项设置为如下。新的设置将保存在他的文件 ~/.cups/lpoptions (或 ~/.lpoptions) 中

 Dest color Resolution=1200dpi Foo=Bar
 Dest mono Colors=Color
 

即使 PPD 文件中没有考虑它们,也可以设置诸如 Resolution=1200dpi 之类的数值和 Foo=Bar 之类的选项。但是,在打印时,将使用 PPD 文件中的默认值(Resolution=300dpi),并且将忽略该选项(Foo=...)。因此,队列 "color" 再次为 "geeko" 在 "earth" 上工作,但设置的值完全不合适。

当 "root" 使用命令 "lpadmin -x mono" 在 "sun" 上删除队列 "mono" 时,~/.cups/lpoptions (或 ~/.lpoptions) 中的现在无效的条目不会被删除,而是保持不变(用户主目录中的文件神圣不可侵犯)。

"root" 再次在 "sun" 上创建队列 "mono",但使用了不同的 PPD 文件

 *DefaultColours: Gray
 *Colours Gray ...
 *Colours Color ...
 ...
 *DefaultResolution: 300x300dpi
 *Resolution 300x300dpi ...
 *Resolution 600x600dpi ...
 

由于选项名称不再匹配("Colours" 而不是 "Colors")或选项值不再匹配("300x300dpi" 和 "600x600dpi" 而不是 "150dpi"、"300dpi" 和 "600dpi"),因此用户 ~/.cups/lpoptions (或 ~/.lpoptions) 文件中的先前条目对于新的队列 "mono" 无效,因此该选项将被忽略或将使用 PPD 文件中的默认值。

设置定义的通用规则

  • 当用户自定义选项时(例如,在他的文件 ~/.cups/lpoptions (或 ~/.lpoptions) 中),这些设置将用于打印作业。
  • 如果计算机上可用文件 /etc/cups/lpoptions,则只有用户尚未定义的选项才会被用于打印作业。
  • 如果在前面的步骤中定义了任何无效选项,则将被忽略。如果任何选项值无效,则将被 PPD 文件中的默认值替换。
  • 对于剩余选项,将使用相应队列的默认值(即 PPD 文件中的默认值)。

该命令

lpoptions -p "queue" -l

显示可能的设置。根据上述规则,将用于打印作业的值以星号 "*" 开头标记。

据此,"earth" 上的用户 "geeko" 可能会使用以下命令

lpoptions -p color -l

以验证通过队列 "color" 进行打印作业将使用哪些设置。他会看到实际使用的设置与他文件 ~/.cups/lpoptions (或 ~/.lpoptions) 中的设置不对应,因为输出将是

 Colors: Gray *Color
 InkCartridge: Black *Color
 Resolution: 150dpi *300dpi 600dpi
 

保持概览的建议

不要在每台机器上单独定义常规预设。在 PPD 文件中设置默认值

  • 如果可能,请勿使用任何 /etc/cups/lpoptions 文件。
  • 如果可能,请勿在每台机器上以 "root" 身份执行命令 "lpoptions"。而是,在 CUPS 服务器上执行命令 "lpadmin"。

手动删除 PPD 文件中任何不合适或不需要的设置,或向 PPD 文件添加适当的约束。

例如,为了避免上述描述的不合适设置,"root" 可以在 CUPS 服务器上手动编辑 PPD 文件 /etc/cups/ppd/mono.ppd 和 /etc/cups/ppd/color.ppd,如下所示

 *DefaultColors: Gray
 *Colors Gray ...
 ...
 *DefaultInkCartridge: Black
 *InkCartridge Black ...
 ...
 *DefaultResolution: 600dpi
 *Resolution 150dpi ...
 *Resolution 300dpi ...
 *Resolution 600dpi ...
 

 *DefaultColors: Color
 *Colors Color ...
 ...
 *DefaultInkCartridge: Color
 *InkCartridge Color ...
 ...
 *DefaultResolution: 300dpi
 *Resolution 150dpi ...
 *Resolution 300dpi ...
 

向 PPD 文件添加适当的约束是另一种解决方案。这些约束通常可以避免用户在图形打印对话框中选择不兼容的值组合,但 PPD 文件中经常缺少适当的约束。带有约束的示例 PPD 文件可能如下所示。请注意,每个约束必须以两种方式指定 - 例如:当选择 "*Colors Gray" 时,则不允许 "*InkCartridge Color",当选择 "*InkCartridge Color" 时,则不允许 "*Colors Gray"。

 *UIConstraints: *Colors Gray *InkCartridge Color
 *UIConstraints: *InkCartridge Color *Colors Gray
 *UIConstraints: *Colors Color *InkCartridge Black
 *UIConstraints: *InkCartridge Black *Colors Color
 *UIConstraints: *Colors Color *Resolution 600dpi
 *UIConstraints: *Resolution 600dpi *Colors Color
 *UIConstraints: *InkCartridge Color *Resolution 600dpi
 *UIConstraints: *Resolution 600dpi *InkCartridge Color
 ...
 *DefaultColors: Color
 *Colors Gray ...
 *Colors Color ...
 ...
 *DefaultInkCartridge: Color
 *InkCartridge Black ...
 *InkCartridge Color ...
 ...
 *DefaultResolution: 300dpi
 *Resolution 150dpi ...
 *Resolution 300dpi ...
 *Resolution 600dpi ...
 

某些值可能适用于打印机,但对于特定的队列而言不受欢迎,例如“草稿”队列的高分辨率。此类选项设置应从特定队列的 PPD 文件中删除。手动更改 PPD 文件后,必须强制 CUPS 守护程序重新读取文件,方法是使用命令 "rccups reload" 或 "rccups restart"。

如果修改导致用户 ~/.cups/lpoptions (或 ~/.lpoptions) 文件中的设置无效,则必须告知用户 CUPS 服务器上的任何队列修改,尤其是在为现有队列使用了不同的 PPD 文件时。

然后,用户可以使用命令

lpoptions -x "queue"

(例如 "lpoptions -x mono")从他们的 ~/.cups/lpoptions (或 ~/.lpoptions) 文件中删除相应的条目,然后用户可以重新配置相关队列的个人设置。

"lpoptions -x" 不适用于已删除的队列。无效条目可以被忽略或手动从 ~/.cups/lpoptions (或 ~/.lpoptions) 文件中删除。

如果应从头开始配置所有个人设置,则应首先使用命令 "rm ~/.cups/lpoptions" (自 CUPS 1.2 / openSUSE 10.2 起) 或使用命令 "rm ~/.lpoptions" (对于 CUPS 1.1) 删除整个文件。

更多信息

Portal:Printing