<< Back to handbook

Chapter 21. CUPS Printing Support

Kurt Pfeifle

Danka Deutschland GmbH

Ciprian Vizitiu

drawings

Jelmer R. Vernooij

drawings
The Samba Team

(27 Jan 2004)

Table of Contents

Introduction
Features and Benefits
Overview
Basic CUPS Support Configuration
Linking smbd with libcups.so
Simple smb.conf Settings for CUPS
More Complex CUPS smb.conf Settings
Advanced Configuration
Central Spooling vs. “Peer-to-Peer” Printing
Raw Print Serving Vendor Drivers on Windows Clients
Installation of Windows Client Drivers
Explicitly Enable “raw” Printing for application/octet-stream
Driver Upload Methods
Advanced Intelligent Printing with PostScript Driver Download
GDI on Windows -- PostScript on UNIX
Windows Drivers, GDI and EMF
UNIX Printfile Conversion and GUI Basics
PostScript and Ghostscript
Ghostscript the Software RIP for Non-PostScript Printers
PostScript Printer Description (PPD) Specification
Using Windows-Formatted Vendor PPDs
CUPS Also Uses PPDs for Non-PostScript Printers
The CUPS Filtering Architecture
MIME Types and CUPS Filters
MIME Type Conversion Rules
Filtering Overview
Prefilters
pstops
pstoraster
imagetops and imagetoraster
rasterto [printers specific]
CUPS Backends
The Role of cupsomatic/foomatic
The Complete Picture
mime.convs
Raw” Printing
application/octet-stream Printing
PostScript Printer Descriptions (PPDs) for Non-PS Printers
cupsomatic/foomatic-rip Versus native CUPS Printing
Examples for Filtering Chains
Sources of CUPS Drivers/PPDs
Printing with Interface Scripts
Network Printing (Purely Windows)
From Windows Clients to an NT Print Server
Driver Execution on the Client
Driver Execution on the Server
Network Printing (Windows Clients UNIX/Samba Print Servers)
From Windows Clients to a CUPS/Samba Print Server
Samba Receiving Job-files and Passing Them to CUPS
Network PostScript RIP
PPDs for Non-PS Printers on UNIX
PPDs for Non-PS Printers on Windows
Windows Terminal Servers (WTS) as CUPS Clients
Printer Drivers Running in “Kernel Mode” Cause Many Problems
Workarounds Impose Heavy Limitations
CUPS: A “Magical Stone”?
PostScript Drivers with No Major Problems Even in Kernel Mode
Configuring CUPS for Driver Download
cupsaddsmb: The Unknown Utility
Prepare Your smb.conf for cupsaddsmb
CUPS “PostScript Driver for Windows NT/200x/XP
Recognizing Different Driver Files
Acquiring the Adobe Driver Files
ESP Print Pro PostScript Driver for Windows NT/200x/XP
Caveats to be Considered
Windows CUPS PostScript Driver Versus Adobe Driver
Run cupsaddsmb (Quiet Mode)
Run cupsaddsmb with Verbose Output
Understanding cupsaddsmb
How to Recognize If cupsaddsmb Completed Successfully
cupsaddsmb with a Samba PDC
cupsaddsmb Flowchart
Installing the PostScript Driver on a Client
Avoiding Critical PostScript Driver Settings on the Client
Installing PostScript Driver Files Manually Using rpcclient
A Check of the rpcclient man Page
Understanding the rpcclient man Page
Producing an Example by Querying a Windows Box
Requirements for adddriver and setdriver to Succeed
Manual Driver Installation in 15 Steps
Troubleshooting Revisited
The Printing *.tdb Files
Trivial Database Files
Binary Format
Losing *.tdb Files
Using tdbbackup
CUPS Print Drivers from Linuxprinting.org
foomatic-rip and Foomatic Explained
foomatic-rip and Foomatic-PPD Download and Installation
Page Accounting with CUPS
Setting Up Quotas
Correct and Incorrect Accounting
Adobe and CUPS PostScript Drivers for Windows Clients
The page_log File Syntax
Possible Shortcomings
Future Developments
Additional Material
Auto-Deletion or Preservation of CUPS Spool Files
CUPS Configuration Settings Explained
Pre-Conditions
Manual Configuration
Printing from CUPS to Windows Attached Printers
More CUPS-Filtering Chains
Common Errors
Windows 9x/ME Client Can't Install Driver
cupsaddsmb” Keeps Asking for Root Password in Never-ending Loop
cupsaddsmb” or “rpcclient addriver” Keeps Giving WERR_BAD_PASSWORD
cupsaddsmb” Errors
Client Can't Connect to Samba Printer
New Account Reconnection from Windows 200x/XP Troubles
Avoid Being Connected to the Samba Server as the Wrong User
Upgrading to CUPS Drivers from Adobe Drivers
Can't Use “cupsaddsmb” on Samba Server Which Is a PDC
Deleted Windows 200x Printer Driver Is Still Shown
Windows 200x/XP "Local Security Policies"
Administrator Cannot Install Printers for All Local Users
Print Change Notify Functions on NT-clients
Win XP-SP1
Print Options for All Users Can't Be Set on Windows 200x/XP
Most Common Blunders in Driver Settings on Windows Clients
cupsaddsmb Does Not Work with Newly Installed Printer
Permissions on /var/spool/samba/ Get Reset After Each Reboot
Print Queue Called “lp” Mis-handles Print Jobs
Location of Adobe PostScript Driver Files for “cupsaddsmb
Overview of the CUPS Printing Processes

Introduction

Features and Benefits

The Common UNIX Print System (CUPS) has become quite popular. All major Linux distributions now ship it as their default printing system. To many, it is still a mystical tool. Mostly, it just works. People tend to regard it as a “black box” that they do not want to look into as long as it works. But once there is a little problem, they are in trouble to find out where to start debugging it. Refer to the chapter “Classical Printing” that contains a lot of information that is relevant for CUPS.

CUPS sports quite a few unique and powerful features. While their basic functions may be grasped quite easily, they are also new. Because they are different from other, more traditional printing systems, it is best not to try and apply any prior knowledge about printing to this new system. Rather, try to understand CUPS from the beginning. This documentation will lead you to a complete understanding of CUPS. Let's start with the most basic things first.

Overview

CUPS is more than just a print spooling system. It is a complete printer management system that complies with the new Internet Printing Protocol (IPP). IPP is an industry and Internet Engineering Task Force (IETF) standard for network printing. Many of its functions can be managed remotely (or locally) via a Web browser (giving you a platform-independent access to the CUPS print server). Additionally, it has the traditional command line and several more modern GUI interfaces (GUI interfaces developed by third parties, like KDE's overwhelming KDEPrint).

CUPS allows creation of “raw” printers (i.e., no print file format translation) as well as “smart” printers (i.e., CUPS does file format conversion as required for the printer). In many ways this gives CUPS similar capabilities to the MS Windows print monitoring system. Of course, if you are a CUPS advocate, you would argue that CUPS is better! In any case, let us now move on to explore how one may configure CUPS for interfacing with MS Windows print clients via Samba.

Basic CUPS Support Configuration

Printing with CUPS in the most basic smb.conf setup in Samba-3.0 (as was true for 2.2.x) only needs two settings: printing = cups and printcap = cups. CUPS does not need a printcap file. However, the cupsd.conf configuration file knows of two related directives that control how such a file will be automatically created and maintained by CUPS for the convenience of third-party applications (example: Printcap /etc/printcap and PrintcapFormat BSD). Legacy programs often require the existence of a printcap file containing printer names or they will refuse to print. Make sure CUPS is set to generate and maintain a printcap file. For details, see man cupsd.conf and other CUPS-related documentation, like the wealth of documents on your CUPS server itself: http://localhost:631/documentation.html.

Linking smbd with libcups.so

Samba has a special relationship to CUPS. Samba can be compiled with CUPS library support. Most recent installations have this support enabled. Per default, CUPS linking is compiled into smbd and other Samba binaries. Of course, you can use CUPS even if Samba is not linked against libcups.so but there are some differences in required or supported configuration.

When Samba is compiled against libcups, printcap = cups uses the CUPS API to list printers, submit jobs, query queues, and so on. Otherwise it maps to the System V commands with an additional -oraw option for printing. On a Linux system, you can use the ldd utility to find out details (ldd may not be present on other OS platforms, or its function may be embodied by a different command):

root# ldd `which smbd`
libssl.so.0.9.6 => /usr/lib/libssl.so.0.9.6 (0x4002d000)
libcrypto.so.0.9.6 => /usr/lib/libcrypto.so.0.9.6 (0x4005a000)
libcups.so.2 => /usr/lib/libcups.so.2 (0x40123000)
[....]

The line libcups.so.2 => /usr/lib/libcups.so.2 (0x40123000) shows there is CUPS support compiled into this version of Samba. If this is the case, and printing = cups is set, then any otherwise manually set print command in smb.conf is ignored. This is an important point to remember!

Tip

Should it be necessary, for any reason, to set your own print commands, you can do this by setting printing = sysv. However, you will lose all the benefits of tight CUPS/Samba integration. When you do this you must manually configure the printing system commands (most important: print command; other commands are lppause command, lpresume command, lpq command, lprm command, queuepause command and queue resume command).

Simple smb.conf Settings for CUPS

To summarize, following example shows simplest printing-related setup for smb.conf to enable basic CUPS support:

Example 21.1. Simplest printing-related smb.conf

[global]
load printers = yes
printing = cups
printcap name = cups
[printers]
comment = All Printers
path = /var/spool/samba
browseable = no
public = yes
guest ok = yes
writable = no
printable = yes
printer admin = root, @ntadmins

This is all you need for basic printing setup for CUPS. It will print all graphic, text, PDF, and PostScript files submitted from Windows clients. However, most of your Windows users would not know how to send these kinds of files to print without opening a GUI application. Windows clients tend to have local printer drivers installed, and the GUI application's print buttons start a printer driver. Your users also rarely send files from the command line. Unlike UNIX clients, they hardly submit graphic, text or PDF formatted files directly to the spooler. They nearly exclusively print from GUI applications with a “printer driver” hooked in between the application's native format and the print-data-stream. If the backend printer is not a PostScript device, the print data stream is “binary,” sensible only for the target printer. Read on to learn which problem this may cause and how to avoid it.

More Complex CUPS smb.conf Settings

Next configuration is a slightly more complex printing-related setup for smb.conf. It enables general CUPS printing support for all printers, but defines one printer share, which is set up differently.

Example 21.2. Overriding global CUPS settings for one printer

[global]
printing = cups
printcap name = cups
load printers = yes
[printers]
comment = All Printers
path = /var/spool/samba
public = yes
guest ok = yes
writable = no
printable = yes
printer admin = root, @ntadmins
[special_printer]
comment = A special printer with his own settings
path = /var/spool/samba-special
printing = sysv
printcap = lpstat
print command = echo "NEW: `date`: printfile %f" \
>> /tmp/smbprn.log ; \
echo " `date`: p-%p s-%s f-%f" >> /tmp/smbprn.log ; \
echo " `date`: j-%j J-%J z-%z c-%c" >> /tmp/smbprn.log ; rm %f
public = no
guest ok = no
writable = no
printable = yes
printer admin = kurt
hosts deny = 0.0.0.0
hosts allow = turbo_xp, 10.160.50.23, 10.160.51.60

This special share is only there for testing purposes. It does not write the print job to a file. It just logs the job parameters known to Samba into the /tmp/smbprn.log file and deletes the job-file. Moreover, the printer admin of this share is “kurt” (not the “@ntadmins” group), guest access is not allowed, the share isn't published to the Network Neighborhood (so you need to know it is there), and it only allows access from only three hosts. To prevent CUPS kicking in and taking over the print jobs for that share, we need to set printing = sysv and printcap = lpstat.

Advanced Configuration

Before we delve into all the configuration options, let us clarify a few points. Network printing needs to be organized and setup correctly. This frequently doesn't happen. Legacy systems or small business LAN environments often lack design and good housekeeping.

Central Spooling vs. “Peer-to-Peer” Printing

Many small office or home networks, as well as badly organized larger environments, allow each client a direct access to available network printers. This is generally a bad idea. It often blocks one client's access to the printer when another client's job is printing. It might freeze the first client's application while it is waiting to get rid of the job. Also, there are frequent complaints about various jobs being printed with their pages mixed with each other. A better concept is the usage of a print server: it routes all jobs through one central system, which responds immediately, takes jobs from multiple concurrent clients at the same time, and in turn transfers them to the printer(s) in the correct order.

Raw Print Serving Vendor Drivers on Windows Clients

Most traditionally configured UNIX print servers acting on behalf of Samba's Windows clients represented a really simple setup. Their only task was to manage the “raw” spooling of all jobs handed to them by Samba. This approach meant that the Windows clients were expected to prepare the print job file that its ready to be sent to the printing device. Here a native (vendor-supplied) Windows printer driver needs to be installed on each and every client for the target device.

It is possible to configure CUPS, Samba and your Windows clients in the same traditional and simple way. When CUPS printers are configured for RAW print-through mode operation, it is the responsibility of the Samba client to fully render the print job (file). The file must be sent in a format that is suitable for direct delivery to the printer. Clients need to run the vendor-provided drivers to do this. In this case, CUPS will not do any print file format conversion work.

The easiest printing configuration possible is to use raw print-through. This is achieved by installation of the printer as if it was physically attached to the Windows client. You then redirect output to a raw network print queue. The following procedure may be followed to achieve this:

  1. Edit /etc/cups/mime.types to uncomment the line near the end of the file that has:

    #application/octet-...
    

  2. Do the same for the file /etc/cups/mime.convs.

  3. Add a raw printer using the Web interface. Point your browser at http://localhost:631. Enter Administration, add the printer following the prompts. Do not install any drivers for it. Choose Raw. Choose queue name Raw Queue.

  4. In the smb.conf file [printers] section add use client driver = Yes, and in the [global] section add printing = CUPS, plus printcap = CUPS.

  5. Install the printer as if it is a local printer. i.e.: Printing to LPT1:.

  6. Edit the configuration under the Detail tab, create a local port that points to the raw printer queue that you have configured above. Example: \\server\raw_q. Here, the name raw_q is the name you gave the print queue in the CUPS environment.

Installation of Windows Client Drivers

The printer drivers on the Windows clients may be installed in two functionally different ways:

  • Manually install the drivers locally on each client, one by one; this yields the old LanMan style printing and uses a \\sambaserver\printershare type of connection.

  • Deposit and prepare the drivers (for later download) on the print server (Samba); this enables the clients to use “Point'n'Print” to get drivers semi-automatically installed the first time they access the printer; with this method NT/200x/XP clients use the SPOOLSS/MS-RPC type printing calls.

The second method is recommended for use over the first.

Explicitly Enable “raw” Printing for application/octet-stream

If you use the first option (drivers are installed on the client side), there is one setting to take care of: CUPS needs to be told that it should allow “raw” printing of deliberate (binary) file formats. The CUPS files that need to be correctly set for RAW mode printers to work are:

  • /etc/cups/mime.types

  • /etc/cups/mime.convs

Both contain entries (at the end of the respective files) which must be uncommented to allow RAW mode operation. In /etc/cups/mime.types, make sure this line is present:

	 application/octet-stream
	

In /etc/cups/mime.convs, have this line:

		application/octet-stream   application/vnd.cups-raw   0   - 
	

If these two files are not set up correctly for raw Windows client printing, you may encounter the dreaded Unable to convert file 0 in your CUPS error_log file.

Note

Editing the mime.convs and the mime.types file does not enforceraw” printing, it only allows it.

Background.  CUPS being a more security-aware printing system than traditional ones does not by default allow a user to send deliberate (possibly binary) data to printing devices. This could be easily abused to launch a “Denial of Service” attack on your printer(s), causing at least the loss of a lot of paper and ink. “Unknown” data are tagged by CUPS as MIME type: application/octet-stream and not allowed to go to the printer. By default, you can only send other (known) MIME types “raw”. Sending data “raw” means that CUPS does not try to convert them and passes them to the printer untouched (see the next chapter for even more background explanations).

This is all you need to know to get the CUPS/Samba combo printing “raw” files prepared by Windows clients, which have vendor drivers locally installed. If you are not interested in background information about more advanced CUPS/Samba printing, simply skip the remaining sections of this chapter.

Driver Upload Methods

This section describes three familiar methods, plus one new one, by which printer drivers may be uploaded.

If you want to use the MS-RPC type printing, you must upload the drivers onto the Samba server first ([print$] share). For a discussion on how to deposit printer drivers on the Samba host (so the Windows clients can download and use them via “Point'n'Print”), please refer to the previous chapter of this HOWTO Collection. There you will find a description or reference to three methods of preparing the client drivers on the Samba server:

  • The GUI, “Add Printer Wizardupload-from-a-Windows-client method.

  • The command line, “smbclient/rpcclient” upload-from-a-UNIX-workstation method.

  • The Imprints Toolset method.

These three methods apply to CUPS all the same. A new and more convenient way to load the Windows drivers into Samba is provided if you use CUPS:

  • the cupsaddsmb utility.

cupsaddsmb is discussed in much detail further below. But we first explore the CUPS filtering system and compare the Windows and UNIX printing architectures.

Advanced Intelligent Printing with PostScript Driver Download

We now know how to set up a “dump” printserver, that is, a server which is spooling print-jobs “raw”, leaving the print data untouched.

Possibly you need to setup CUPS in a smarter way. The reasons could be manifold:

  • Maybe your boss wants to get monthly statistics: Which printer did how many pages? What was the average data size of a job? What was the average print run per day? What are the typical hourly peaks in printing? Which department prints how much?

  • Maybe you are asked to setup a print quota system: Users should not be able to print more jobs, once they have surpassed a given limit per period.

  • Maybe your previous network printing setup is a mess and must be re-organized from a clean beginning.

  • Maybe you have experiencing too many “blue screens” originating from poorly debugged printer drivers running in NT “kernel mode”?

These goals cannot be achieved by a raw print server. To build a server meeting these requirements, you'll first need to learn about how CUPS works and how you can enable its features.

What follows is the comparison of some fundamental concepts for Windows and UNIX printing; then follows a description of the CUPS filtering system, how it works and how you can tweak it.

GDI on Windows -- PostScript on UNIX

Network printing is one of the most complicated and error-prone day-to-day tasks any user or administrator may encounter. This is true for all OS platforms. And there are reasons for this.

You can't expect most file formats to just throw them toward printers and they get printed. There needs to be a file format conversion in between. The problem is that there is no common standard for print file formats across all manufacturers and printer types. While PostScript (trademark held by Adobe) and, to an extent, PCL (trademark held by HP) have developed into semi-official “standards” by being the most widely used PDLs Page Description Languages (PDLs), there are still many manufacturers who “roll their own” (their reasons may be unacceptable license fees for using printer-embedded PostScript interpreters, and so on).

Windows Drivers, GDI and EMF

In Windows OS, the format conversion job is done by the printer drivers. On MS Windows OS platforms all application programmers have at their disposal a built-in API, the Graphical Device Interface (GDI), as part and parcel of the OS itself to base themselves on. This GDI core is used as one common unified ground for all Windows programs to draw pictures, fonts and documents on screen as well as on paper (print). Therefore, printer driver developers can standardize on a well-defined GDI output for their own driver input. Achieving WYSIWYG (“What You See Is What You Get”) is relatively easy, because the on-screen graphic primitives, as well as the on-paper drawn objects, come from one common source. This source, the GDI, often produces a file format called Enhanced MetaFile (EMF). The EMF is processed by the printer driver and converted to the printer-specific file format.

Note

To the GDI foundation in MS Windows, Apple has chosen to put paper and screen output on a common foundation for their (BSD-UNIX-based, did you know?) Mac OS X and Darwin Operating Systems. Their Core Graphic Engine uses a PDF derivative for all display work.

Figure 21.1. Windows printing to a local printer.

Windows printing to a local printer.

UNIX Printfile Conversion and GUI Basics

In UNIX and Linux, there is no comparable layer built into the OS kernel(s) or the X (screen display) server. Every application is responsible for itself to create its print output. Fortunately, most use PostScript and that at least gives some common ground. Unfortunately, there are many different levels of quality for this PostScript. And worse, there is a huge difference (and no common root) in the way the same document is displayed on screen and how it is presented on paper. WYSIWYG is more difficult to achieve. This goes back to the time, decades ago, when the predecessors of X.org, designing the UNIX foundations and protocols for Graphical User Interfaces, refused to take responsibility for “paper output” also, as some had demanded at the time, and restricted itself to “on-screen only.” (For some years now, the “Xprint” project has been under development, attempting to build printing support into the X framework, including a PostScript and a PCL driver, but it is not yet ready for prime time.) You can see this unfavorable inheritance up to the present day by looking into the various “font” directories on your system; there are separate ones for fonts used for X display and fonts to be used on paper.

Background.  The PostScript programming language is an “invention” by Adobe Inc., but its specifications have been published to the full. Its strength lies in its powerful abilities to describe graphical objects (fonts, shapes, patterns, lines, curves, and dots), their attributes (color, linewidth) and the way to manipulate (scale, distort, rotate, shift) them. Because of its open specification, anybody with the skill can start writing his own implementation of a PostScript interpreter and use it to display PostScript files on screen or on paper. Most graphical output devices are based on the concept of “raster images” or “pixels” (one notable exception is pen plotters). Of course, you can look at a PostScript file in its textual form and you will be reading its PostScript code, the language instructions which need to be interpreted by a rasterizer. Rasterizers produce pixel images, which may be displayed on screen by a viewer program or on paper by a printer.

PostScript and Ghostscript

So, UNIX is lacking a common ground for printing on paper and displaying on screen. Despite this unfavorable legacy for UNIX, basic printing is fairly easy if you have PostScript printers at your disposal. The reason is these devices have a built-in PostScript language “interpreter,” also called a Raster Image Processor (RIP) (which makes them more expensive than other types of printers); throw PostScript toward them, and they will spit out your printed pages. Their RIP is doing all the hard work of converting the PostScript drawing commands into a bitmap picture as you see it on paper, in a resolution as done by your printer. This is no different to PostScript printing a file from a Windows origin.

Note

Traditional UNIX programs and printing systems while using PostScript are largely not PPD-aware. PPDs are “PostScript Printer Description” files. They enable you to specify and control all options a printer supports: duplexing, stapling and punching. Therefore, UNIX users for a long time couldn't choose many of the supported device and job options, unlike Windows or Apple users. But now there is CUPS.

Figure 21.2. Printing to a PostScript printer.

Printing to a PostScript printer.

However, there are other types of printers out there. These do not know how to print PostScript. They use their own Page Description Language (PDL, often proprietary). To print to them is much more demanding. Since your UNIX applications mostly produce PostScript, and since these devices do not understand PostScript, you need to convert the print files to a format suitable for your printer on the host before you can send it away.

Ghostscript the Software RIP for Non-PostScript Printers

Here is where Ghostscript kicks in. Ghostscript is the traditional (and quite powerful) PostScript interpreter used on UNIX platforms. It is a RIP in software, capable of doing a lot of file format conversions for a very broad spectrum of hardware devices as well as software file formats. Ghostscript technology and drivers are what enable PostScript printing to non-PostScript hardware.

Figure 21.3. Ghostscript as a RIP for non-postscript printers.

Ghostscript as a RIP for non-postscript printers.

Tip

Use the “gs -h” command to check for all built-in “devices” of your Ghostscript version. If you specify a parameter of -sDEVICE=png256 on your Ghostscript command line, you are asking Ghostscript to convert the input into a PNG file. Naming a “device” on the command line is the most important single parameter to tell Ghostscript exactly how it should render the input. New Ghostscript versions are released at fairly regular intervals, now by artofcode LLC. They are initially put under the “AFPL” license, but re-released under the GNU GPL as soon as the next AFPL version appears. GNU Ghostscript is probably the version installed on most Samba systems. But it has some deficiencies. Therefore, ESP Ghostscript was developed as an enhancement over GNU Ghostscript, with lots of bug-fixes, additional devices and improvements. It is jointly maintained by developers from CUPS, Gimp-Print, MandrakeSoft, SuSE, Red Hat, and Debian. It includes the “cups” device (essential to print to non-PS printers from CUPS).

PostScript Printer Description (PPD) Specification

While PostScript in essence is a Page Description Language (PDL) to represent the page layout in a device-independent way, real-world print jobs are always ending up being output on hardware with device-specific features. To take care of all the differences in hardware and to allow for innovations, Adobe has specified a syntax and file format for PostScript Printer Description (PPD) files. Every PostScript printer ships with one of these files.

PPDs contain all the information about general and special features of the given printer model: Which different resolutions can it handle? Does it have a Duplexing Unit? How many paper trays are there? What media types and sizes does it take? For each item, it also names the special command string to be sent to the printer (mostly inside the PostScript file) in order to enable it.

Information from these PPDs is meant to be taken into account by the printer drivers. Therefore, installed as part of the Windows PostScript driver for a given printer is the printer's PPD. Where it makes sense, the PPD features are presented in the drivers' UI dialogs to display to the user a choice of print options. In the end, the user selections are somehow written (in the form of special PostScript, PJL, JCL or vendor-dependent commands) into the PostScript file created by the driver.

Warning

A PostScript file that was created to contain device-specific commands for achieving a certain print job output (e.g., duplex-ed, stapled and punched) on a specific target machine, may not print as expected, or may not be printable at all on other models; it also may not be fit for further processing by software (e.g., by a PDF distilling program).

Using Windows-Formatted Vendor PPDs

CUPS can handle all spec-compliant PPDs as supplied by the manufacturers for their PostScript models. Even if a vendor might not have mentioned our favorite OS in his manuals and brochures, you can safely trust this: If you get the Windows NT version of the PPD, you can use it unchanged in CUPS and thus access the full power of your printer just like a Windows NT user could!

Tip

To check the spec compliance of any PPD online, go to http://www.cups.org/testppd.php and upload your PPD. You will see the results displayed immediately. CUPS in all versions after 1.1.19 has a much more strict internal PPD parsing and checking code enabled; in case of printing trouble, this online resource should be one of your first pit-stops.

Warning

For real PostScript printers, do not use the Foomatic or cupsomatic PPDs from Linuxprinting.org. With these devices, the original vendor-provided PPDs are always the first choice!

Tip

If you are looking for an original vendor-provided PPD of a specific device, and you know that an NT4 box (or any other Windows box) on your LAN has the PostScript driver installed, just use smbclient //NT4-box/print\$ -U username to access the Windows directory where all printer driver files are stored. First look in the W32X86/2 subdir for the PPD you are seeking.

CUPS Also Uses PPDs for Non-PostScript Printers

CUPS also uses specially crafted PPDs to handle non-PostScript printers. These PPDs are usually not available from the vendors (and no, you can't just take the PPD of a PostScript printer with the same model name and hope it works for the non-PostScript version too). To understand how these PPDs work for non-PS printers, we first need to dive deeply into the CUPS filtering and file format conversion architecture. Stay tuned.

The CUPS Filtering Architecture

The core of the CUPS filtering system is based on Ghostscript. In addition to Ghostscript, CUPS uses some other filters of its own. You (or your OS vendor) may have plugged in even more filters. CUPS handles all data file formats under the label of various MIME types. Every incoming printfile is subjected to an initial auto-typing. The auto-typing determines its given MIME type. A given MIME type implies zero or more possible filtering chains relevant to the selected target printer. This section discusses how MIME types recognition and conversion rules interact. They are used by CUPS to automatically setup a working filtering chain for any given input data format.

If CUPS rasterizes a PostScript file natively to a bitmap, this is done in two stages:

  • The first stage uses a Ghostscript device named “cups” (this is since version 1.1.15) and produces a generic raster format called “CUPS raster”.

  • The second stage uses a “raster driver” that converts the generic CUPS raster to a device-specific raster.

Make sure your Ghostscript version has the “cups” device compiled in (check with gs -h | grep cups). Otherwise you may encounter the dreaded Unable to convert file 0 in your CUPS error_log file. To have “cups” as a device in your Ghostscript, you either need to patch GNU Ghostscript and re-compile, or use ESP Ghostscript. The superior alternative is ESP Ghostscript. It supports not just CUPS, but 300 other devices too (while GNU Ghostscript supports only about 180). Because of this broad output device support, ESP Ghostscript is the first choice for non-CUPS spoolers, too. It is now recommended by Linuxprinting.org for all spoolers.

CUPS printers may be setup to use external rendering paths. One of the most common is provided by the Foomatic/cupsomatic concept from Linuxprinting.org. This uses the classical Ghostscript approach, doing everything in one step. It does not use the “cups” device, but one of the many others. However, even for Foomatic/cupsomatic usage, best results and broadest printer model support is provided by ESP Ghostscript (more about cupsomatic/Foomatic, particularly the new version called now foomatic-rip, follows below).

MIME Types and CUPS Filters

CUPS reads the file /etc/cups/mime.types (and all other files carrying a *.types suffix in the same directory) upon startup. These files contain the MIME type recognition rules that are applied when CUPS runs its auto-typing routines. The rule syntax is explained in the man page for mime.types and in the comments section of the mime.types file itself. A simple rule reads like this:

 application/pdf         pdf string(0,%PDF)

This means if a filename has either a .pdf suffix or if the magic string %PDF is right at the beginning of the file itself (offset 0 from the start), then it is a PDF file (application/pdf). Another rule is this:

 application/postscript  ai eps ps string(0,%!) string(0,<04>%!)

If the filename has one of the suffixes .ai, .eps, .ps or if the file itself starts with one of the strings %! or <04>%!, it is a generic PostScript file (application/postscript).

Warning

Don't confuse the other mime.types files your system might be using with the one in the /etc/cups/ directory.

Note

There is an important difference between two similar MIME types in CUPS: one is application/postscript, the other is application/vnd.cups-postscript. While application/postscript is meant to be device independent (job options for the file are still outside the PS file content, embedded in command line or environment variables by CUPS), application/vnd.cups-postscript may have the job options inserted into the PostScript data itself (where applicable). The transformation of the generic PostScript (application/postscript) to the device-specific version (application/vnd.cups-postscript) is the responsibility of the CUPS pstops filter. pstops uses information contained in the PPD to do the transformation.

CUPS can handle ASCII text, HP-GL, PDF, PostScript, DVI, and many image formats (GIF. PNG, TIFF, JPEG, Photo-CD, SUN-Raster, PNM, PBM, SGI-RGB, and more) and their associated MIME types with its filters.

MIME Type Conversion Rules

CUPS reads the file /etc/cups/mime.convs (and all other files named with a *.convs suffix in the same directory) upon startup. These files contain lines naming an input MIME type, an output MIME type, a format conversion filter that can produce the output from the input type and virtual costs associated with this conversion. One example line reads like this:

 application/pdf         application/postscript   33   pdftops

This means that the pdftops filter will take application/pdf as input and produce application/postscript as output; the virtual cost of this operation is 33 CUPS-$. The next filter is more expensive, costing 66 CUPS-$:

 application/vnd.hp-HPGL application/postscript   66   hpgltops

This is the hpgltops, which processes HP-GL plotter files to PostScript.

 application/octet-stream

Here are two more examples:

 application/x-shell     application/postscript   33    texttops
 text/plain              application/postscript   33    texttops

The last two examples name the texttops filter to work on text/plain as well as on application/x-shell. (Hint: This differentiation is needed for the syntax highlighting feature of texttops).

Filtering Overview

There are many more combinations named in mime.convs. However, you are not limited to use the ones pre-defined there. You can plug in any filter you like into the CUPS framework. It must meet, or must be made to meet, some minimal requirements. If you find (or write) a cool conversion filter of some kind, make sure it complies to what CUPS needs and put in the right lines in mime.types and mime.convs, then it will work seamlessly inside CUPS.

Filter requirements

The mentioned “CUPS requirements” for filters are simple. Take filenames or stdin as input and write to stdout. They should take these 5 or 6 arguments: printer job user title copies options [filename]

Printer

The name of the printer queue (normally this is the name of the filter being run).

job

The numeric job ID for the job being printed.

user

The string from the originating-user-name attribute.

title

The string from the job-name attribute.

copies

The numeric value from the number-copies attribute.

options

The job options.

filename

(Optionally) The print request file (if missing, filters expected data fed through stdin). In most cases, it is easy to write a simple wrapper script around existing filters to make them work with CUPS.

Prefilters

As previously stated, PostScript is the central file format to any UNIX-based printing system. From PostScript, CUPS generates raster data to feed non-PostScript printers.

But what happens if you send one of the supported non-PS formats to print? Then CUPS runs “pre-filters” on these input formats to generate PostScript first. There are pre-filters to create PS from ASCII text, PDF, DVI, or HP-GL. The outcome of these filters is always of MIME type application/postscript (meaning that any device-specific print options are not yet embedded into the PostScript by CUPS, and that the next filter to be called is pstops). Another pre-filter is running on all supported image formats, the imagetops filter. Its outcome is always of MIME type application/vnd.cups-postscript (not application/postscript), meaning it has the print options already embedded into the file.

Figure 21.4. Pre-filtering in CUPS to form PostScript.

Pre-filtering in CUPS to form PostScript.

pstops

pstops is the filter to convert application/postscript to application/vnd.cups-postscript. It was said above that this filter inserts all device-specific print options (commands to the printer to ask for the duplexing of output, or stapling and punching it, and so on) into the PostScript file.

Figure 21.5. Adding device-specific print options.

Adding device-specific print options.

This is not all. Other tasks performed by it are:

  • Selecting the range of pages to be printed (if you choose to print only pages “3, 6, 8-11, 16, 19-21”, or only the odd numbered ones).

  • Putting 2 or more logical pages on one sheet of paper (the so-called “number-up” function).

  • Counting the pages of the job to insert the accounting information into the /var/log/cups/page_log.

pstoraster

pstoraster is at the core of the CUPS filtering system. It is responsible for the first stage of the rasterization process. Its input is of MIME type application/vnd.cups-postscript; its output is application/vnd.cups-raster. This output format is not yet meant to be printable. Its aim is to serve as a general purpose input format for more specialized raster drivers that are able to generate device-specific printer data.

Figure 21.6. PostScript to intermediate raster format.

PostScript to intermediate raster format.

CUPS raster is a generic raster format with powerful features. It is able to include per-page information, color profiles, and more, to be used by the following downstream raster drivers. Its MIME type is registered with IANA and its specification is, of course, completely open. It is designed to make it quite easy and inexpensive for manufacturers to develop Linux and UNIX raster drivers for their printer models, should they choose to do so. CUPS always takes care for the first stage of rasterization so these vendors do not need to care about Ghostscript complications (in fact, there is currently more than one vendor financing the development of CUPS raster drivers).

Figure 21.7. CUPS-raster production using Ghostscript.

CUPS-raster production using Ghostscript.

CUPS versions before version 1.1.15 were shipping a binary (or source code) standalone filter, named pstoraster. pstoraster was derived from GNU Ghostscript 5.50, and could be installed besides and in addition to any GNU or AFPL Ghostscript package without conflicting.

>From version 1.1.15, this has changed. The functions for this have been integrated back into Ghostscript (now based on GNU Ghostscript version 7.05). The pstoraster filter is now a simple shell script calling gs with the -sDEVICE=cups parameter. If your Ghostscript does not show a success on asking for gs -h |grep cups, you might not be able to print. Update your Ghostscript.

imagetops and imagetoraster

In the section about pre-filters, we mentioned the pre-filter that generates PostScript from image formats. The imagetoraster filter is used to convert directly from image to raster, without the intermediate PostScript stage. It is used more often than the above mentioned pre-filters. We summarize flowchart of image file filtering on next picture.

Figure 21.8. Image format to CUPS-raster format conversion.

Image format to CUPS-raster format conversion.

rasterto [printers specific]

CUPS ships with quite different raster drivers processing CUPS raster. On my system I find in /usr/lib/cups/filter/ these: rastertoalps, rastertobj, rastertoepson, rastertoescp, rastertopcl, rastertoturboprint, rastertoapdk, rastertodymo, rastertoescp, rastertohp, and rastertoprinter. Don't worry if you have less than this; some of these are installed by commercial add-ons to CUPS (like rastertoturboprint), others (like rastertoprinter) by third-party driver development projects (such as Gimp-Print) wanting to cooperate as closely as possible with CUPS.

Figure 21.9. Raster to printer-specific formats.

Raster to printer-specific formats.

CUPS Backends

The last part of any CUPS filtering chain is a backend. Backends are special programs that send the print-ready file to the final device. There is a separate backend program for any transfer protocol of sending print jobs over the network, or for every local interface. Every CUPS print queue needs to have a CUPS “device-URI” associated with it. The device URI is the way to encode the backend used to send the job to its destination. Network device-URIs are using two slashes in their syntax, local device URIs only one, as you can see from the following list. Keep in mind that local interface names may vary much from my examples, if your OS is not Linux:

usb

This backend sends print files to USB-connected printers. An example for the CUPS device-URI to use is: usb:/dev/usb/lp0.

serial

This backend sends print files to serially connected printers. An example for the CUPS device-URI to use is: serial:/dev/ttyS0?baud=11500.

parallel

This backend sends print files to printers connected to the parallel port. An example for the CUPS device-URI to use is: parallel:/dev/lp0.

SCSI

This backend sends print files to printers attached to the SCSI interface. An example for the CUPS device-URI to use is: scsi:/dev/sr1.

lpd

This backend sends print files to LPR/LPD connected network printers. An example for the CUPS device-URI to use is: lpd://remote_host_name/remote_queue_name.

AppSocket/HP JetDirect

This backend sends print files to AppSocket (a.k.a. "HP JetDirect") connected network printers. An example for the CUPS device-URI to use is: socket://10.11.12.13:9100.

ipp

This backend sends print files to IPP connected network printers (or to other CUPS servers). Examples for CUPS device-URIs to use are: ipp:://192.193.194.195/ipp (for many HP printers) or ipp://remote_cups_server/printers/remote_printer_name.

http

This backend sends print files to HTTP connected printers. (The http:// CUPS backend is only a symlink to the ipp:// backend.) Examples for the CUPS device-URIs to use are: http:://192.193.194.195:631/ipp (for many HP printers) or http://remote_cups_server:631/printers/remote_printer_name.

smb

This backend sends print files to printers shared by a Windows host. An example for CUPS device-URIs that may be used includes:

smb://workgroup/server/printersharename
smb://server/printersharename
smb://username:password@workgroup/server/printersharename
smb://username:password@server/printersharename

The smb:// backend is a symlink to the Samba utility smbspool (does not ship with CUPS). If the symlink is not present in your CUPS backend directory, have your root user create it: ln -s `which smbspool' /usr/lib/cups/backend/smb.

It is easy to write your own backends as shell or Perl scripts, if you need any modification or extension to the CUPS print system. One reason could be that you want to create “special” printers that send the print-jobs as email (through a “mailto:/” backend), convert them to PDF (through a “pdfgen:/” backend) or dump them to “/dev/null”. (In fact I have the system-wide default printer set up to be connected to a devnull:/ backend: there are just too many people sending jobs without specifying a printer, or scripts and programs which do not name a printer. The system-wide default deletes the job and sends a polite email back to the $USER asking him to always specify the correct printer name.)

Not all of the mentioned backends may be present on your system or usable (depending on your hardware configuration). One test for all available CUPS backends is provided by the lpinfo utility. Used with the -v parameter, it lists all available backends:

$ lpinfo -v

The Role of cupsomatic/foomatic

cupsomatic filters may be the most widely used on CUPS installations. You must be clear about the fact that these were not developed by the CUPS people. They are a third party add-on to CUPS. They utilize the traditional Ghostscript devices to render jobs for CUPS. When troubleshooting, you should know about the difference. Here the whole rendering process is done in one stage, inside Ghostscript, using an appropriate device for the target printer. cupsomatic uses PPDs that are generated from the Foomatic Printer & Driver Database at Linuxprinting.org.

You can recognize these PPDs from the line calling the cupsomatic filter:

 *cupsFilter: "application/vnd.cups-postscript  0  cupsomatic"

You may find this line among the first 40 or so lines of the PPD file. If you have such a PPD installed, the printer shows up in the CUPS Web interface with a foomatic namepart for the driver description. cupsomatic is a Perl script that runs Ghostscript with all the complicated command line options auto-constructed from the selected PPD and command line options give to the print-job.

However, cupsomatic is now deprecated. Its PPDs (especially the first generation of them, still in heavy use out there) are not meeting the Adobe specifications. You might also suffer difficulties when you try to download them with “Point'n'Print” to Windows clients. A better and more powerful successor is now in a stable beta-version: it is called foomatic-rip. To use foomatic-rip as a filter with CUPS, you need the new-type PPDs. These have a similar but different line:

 *cupsFilter: "application/vnd.cups-postscript  0  foomatic-rip"

The PPD generating engine at Linuxprinting.org has been revamped. The new PPDs comply to the Adobe spec. On top, they also provide a new way to specify different quality levels (hi-res photo, normal color, grayscale, and draft) with a single click, whereas before you could have required five or more different selections (media type, resolution, inktype and dithering algorithm). There is support for custom-size media built in. There is support to switch print-options from page to page in the middle of a job. And the best thing is the new foomatic-rip now works seamlessly with all legacy spoolers too (like LPRng, BSD-LPD, PDQ, PPR and so on), providing for them access to use PPDs for their printing.

The Complete Picture

If you want to see an overview of all the filters and how they relate to each other, the complete picture of the puzzle is at the end of this document.

mime.convs

CUPS auto-constructs all possible filtering chain paths for any given MIME type, and every printer installed. But how does it decide in favor or against a specific alternative? (There may often be cases where there is a choice of two or more possible filtering chains for the same target printer.) Simple. You may have noticed the figures in the third column of the mime.convs file. They represent virtual costs assigned to this filter. Every possible filtering chain will sum up to a total “filter cost.” CUPS decides for the most “inexpensive” route.

Tip

The setting of FilterLimit 1000 in cupsd.conf will not allow more filters to run concurrently than will consume a total of 1000 virtual filter cost. This is an efficient way to limit the load of any CUPS server by setting an appropriate “FilterLimit” value. A FilterLimit of 200 allows roughly one job at a time, while a FilterLimit of 1000 allows approximately five jobs maximum at a time.

Raw” Printing

You can tell CUPS to print (nearly) any file “raw”. “Raw” means it will not be filtered. CUPS will send the file to the printer “as is” without bothering if the printer is able to digest it. Users need to take care themselves that they send sensible data formats only. Raw printing can happen on any queue if the “-o raw” option is specified on the command line. You can also set up raw-only queues by simply not associating any PPD with it. This command:

$ lpadmin -P rawprinter -v socket://11.12.13.14:9100 -E

sets up a queue named “rawprinter”, connected via the “socket” protocol (a.k.a. “HP JetDirect”) to the device at IP address 11.12.1.3.14, using port 9100. (If you had added a PPD with -P /path/to/PPD to this command line, you would have installed a “normal” print queue.

CUPS will automatically treat each job sent to a queue as a “raw” one, if it can't find a PPD associated with the queue. However, CUPS will only send known MIME types (as defined in its own mime.types file) and refuse others.

application/octet-stream Printing

Any MIME type with no rule in the /etc/cups/mime.types file is regarded as unknown or application/octet-stream and will not be sent. Because CUPS refuses to print unknown MIME types per default, you will probably have experienced the fact that print jobs originating from Windows clients were not printed. You may have found an error message in your CUPS logs like:

Unable to convert file 0 to printable format for job

To enable the printing of application/octet-stream files, edit these two files:

  • /etc/cups/mime.convs

  • /etc/cups/mime.types

Both contain entries (at the end of the respective files) which must be uncommented to allow RAW mode operation for application/octet-stream. In /etc/cups/mime.types make sure this line is present:

application/octet-stream

This line (with no specific auto-typing rule set) makes all files not otherwise auto-typed a member of application/octet-stream. In /etc/cups/mime.convs, have this line:

application/octet-stream   application/vnd.cups-raw   0   -

This line tells CUPS to use the Null Filter (denoted as “-”, doing nothing at all) on application/octet-stream, and tag the result as application/vnd.cups-raw. This last one is always a green light to the CUPS scheduler to now hand the file over to the backend connecting to the printer and sending it over.

Note

Editing the mime.convs and the mime.types file does not enforceraw” printing, it only allows it.

Background.  CUPS being a more security-aware printing system than traditional ones does not by default allow one to send deliberate (possibly binary) data to printing devices. (This could be easily abused to launch a Denial of Service attack on your printer(s), causing at least the loss of a lot of paper and ink...) “Unknown” data are regarded by CUPS as MIME type application/octet-stream. While you can send data “raw”, the MIME type for these must be one that is known to CUPS and an allowed one. The file /etc/cups/mime.types defines the “rules” of how CUPS recognizes MIME types. The file /etc/cups/mime.convs decides which file conversion filter(s) may be applied to which MIME types.

PostScript Printer Descriptions (PPDs) for Non-PS Printers

Originally PPDs were meant to be used for PostScript printers only. Here, they help to send device-specific commands and settings to the RIP which processes the job file. CUPS has extended this scope for PPDs to cover non-PostScript printers too. This was not difficult, because it is a standardized file format. In a way it was logical too: CUPS handles PostScript and uses a PostScript RIP (Ghostscript) to process the job files. The only difference is: a PostScript printer has the RIP built-in, for other types of printers the Ghostscript RIP runs on the host computer.

PPDs for a non-PS printer have a few lines that are unique to CUPS. The most important one looks similar to this:

 *cupsFilter: application/vnd.cups-raster  66   rastertoprinter

It is the last piece in the CUPS filtering puzzle. This line tells the CUPS daemon to use as a last filter rastertoprinter. This filter should be served as input an application/vnd.cups-raster MIME type file. Therefore, CUPS should auto-construct a filtering chain, which delivers as its last output the specified MIME type. This is then taken as input to the specified rastertoprinter filter. After this the last filter has done its work (rastertoprinter is a Gimp-Print filter), the file should go to the backend, which sends it to the output device.

CUPS by default ships only a few generic PPDs, but they are good for several hundred printer models. You may not be able to control different paper trays, or you may get larger margins than your specific model supports. See PPDs shipped with CUPS for summary information.

Table 21.1. PPDs shipped with CUPS

PPD filePrinter type
deskjet.ppdolder HP inkjet printers and compatible
deskjet2.ppdnewer HP inkjet printers and compatible
dymo.ppdlabel printers
epson9.ppdEpson 24pin impact printers and compatible
epson24.ppdEpson 24pin impact printers and compatible
okidata9.ppdOkidata 9pin impact printers and compatible
okidat24.ppdOkidata 24pin impact printers and compatible
stcolor.ppdolder Epson Stylus Color printers
stcolor2.ppdnewer Epson Stylus Color printers
stphoto.ppdolder Epson Stylus Photo printers
stphoto2.ppdnewer Epson Stylus Photo printers
laserjet.ppdall PCL printers. Further below is a discussion of several other driver/PPD-packages suitable for use with CUPS.

cupsomatic/foomatic-rip Versus native CUPS Printing

Native CUPS rasterization works in two steps:

  • First is the pstoraster step. It uses the special CUPS device from ESP Ghostscript 7.05.x as its tool.

  • Second comes the rasterdriver step. It uses various device-specific filters; there are several vendors who provide good quality filters for this step. Some are free software, some are shareware/non-free and some are proprietary.

Often this produces better quality (and has several more advantages) than other methods.

Figure 21.10. cupsomatic/foomatic Processing versus Native CUPS.

cupsomatic/foomatic Processing versus Native CUPS.

One other method is the cupsomatic/foomatic-rip way. Note that cupsomatic is not made by the CUPS developers. It is an independent contribution to printing development, made by people from Linuxprinting.org [5]. cupsomatic is no longer developed and maintained and is no longer supported. It has now been replaced by foomatic-rip. foomatic-rip is a complete re-write of the old cupsomatic idea, but very much improved and generalized to other (non-CUPS) spoolers. An upgrade to foomatic-rip is strongly advised, especially if you are upgrading to a recent version of CUPS, too.

Both the cupsomatic (old) and the foomatic-rip (new) methods from Linuxprinting.org use the traditional Ghostscript print file processing, doing everything in a single step. It therefore relies on all the other devices built into Ghostscript. The quality is as good (or bad) as Ghostscript rendering is in other spoolers. The advantage is that this method supports many printer models not supported (yet) by the more modern CUPS method.

Of course, you can use both methods side by side on one system (and even for one printer, if you set up different queues) and find out which works best for you.

cupsomatic kidnaps the printfile after the application/vnd.cups-postscript stage and deviates it through the CUPS-external, system-wide Ghostscript installation. Therefore the printfile bypasses the pstoraster filter (and also bypasses the CUPS-raster-drivers rastertosomething). After Ghostscript finished its rasterization, cupsomatic hands the rendered file directly to the CUPS backend. The flowchart in cupsomatic/foomatic processing versus Native CUPS illustrates the difference between native CUPS rendering and the Foomatic/cupsomatic method.

Examples for Filtering Chains

Here are a few examples of commonly occurring filtering chains to illustrate the workings of CUPS.

Assume you want to print a PDF file to an HP JetDirect-connected PostScript printer, but you want to print the pages 3-5, 7, 11-13 only, and you want to print them “two-up” and “duplex”:

  • Your print options (page selection as required, two-up, duplex) are passed to CUPS on the command line.

  • The (complete) PDF file is sent to CUPS and auto-typed as application/pdf.

  • The file therefore must first pass the pdftops pre-filter, which produces PostScript MIME type application/postscript (a preview here would still show all pages of the original PDF).

  • The file then passes the pstops filter that applies the command line options: it selects the pages 2-5, 7 and 11-13, creates an imposed layout “2 pages on 1 sheet” and inserts the correct “duplex” command (as defined in the printer's PPD) into the new PostScript file; the file is now of PostScript MIME type application/vnd.cups-postscript.

  • The file goes to the socket backend, which transfers the job to the printers.

The resulting filter chain, therefore, is as drawn in PDF to socket chain.

Figure 21.11. PDF to socket chain.

PDF to socket chain.

Assume you want to print the same filter to an USB-connected Epson Stylus Photo printer installed with the CUPS stphoto2.ppd. The first few filtering stages are nearly the same:

  • Your print options (page selection as required, two-up, duplex) are passed to CUPS on the command-line.

  • The (complete) PDF file is sent to CUPS and auto-typed as application/pdf.

  • The file must first pass the pdftops pre-filter, which produces PostScript MIME type application/postscript (a preview here would still show all pages of the original PDF).

  • The file then passes the “pstops” filter that applies the command-line options: it selects the pages 2-5, 7 and 11-13, creates an imposed layout “two pages on one sheet” and inserts the correct “duplex” command... (Oops this printer and PPD do not support duplex printing at all so this option will be ignored) into the new PostScript file; the file is now of PostScript MIME type application/vnd.cups-postscript.

  • The file then passes the pstoraster stage and becomes MIME type application/ cups-raster.

  • Finally, the rastertoepson filter does its work (as indicated in the printer's PPD), creating the printer-specific raster data and embedding any user-selected print-options into the print data stream.

  • The file goes to the usb backend, which transfers the job to the printers.

The resulting filter chain therefore is as drawn in this figure.

Figure 21.12. PDF to USB chain.

PDF to USB chain.

Sources of CUPS Drivers/PPDs

On the Internet you can now find many thousands of CUPS-PPD files (with their companion filters), in many national languages supporting more than thousand non-PostScript models.

  • ESP PrintPro (commercial, non-free) is packaged with more than three thousand PPDs, ready for successful use “out of the box” on Linux, Mac OS X, IBM-AIX, HP-UX, Sun-Solaris, SGI-IRIX, Compaq Tru64, Digital UNIX, and some more commercial Unices (it is written by the CUPS developers themselves and its sales help finance the further development of CUPS, as they feed their creators).

  • The Gimp-Print-Project (GPL, free software) provides around 140 PPDs (supporting nearly 400 printers, many driven to photo quality output), to be used alongside the Gimp-Print CUPS filters.

  • TurboPrint (shareware, non-free) supports roughly the same amount of printers in excellent quality.

  • OMNI (LPGL, free) is a package made by IBM, now containing support for more than 400 printers, stemming from the inheritance of IBM OS/2 Know-How ported over to Linux (CUPS support is in a beta-stage at present).

  • HPIJS (BSD-style licenses, free) supports around 150 of HP's own printers and is also providing excellent print quality now (currently available only via the Foomatic path).

  • Foomatic/cupsomatic (LPGL, free) from Linuxprinting.org are providing PPDs for practically every Ghostscript filter known to the world (including Omni, Gimp-Print and HPIJS).

Printing with Interface Scripts

CUPS also supports the usage of “interface scripts” as known from System V AT&T printing systems. These are often used for PCL printers, from applications that generate PCL print jobs. Interface scripts are specific to printer models. They have a similar role as PPDs for PostScript printers. Interface scripts may inject the Escape sequences as required into the print data stream, if the user has chosen to select a certain paper tray, or print landscape, or use A3 paper, etc. Interfaces scripts are practically unknown in the Linux realm. On HP-UX platforms they are more often used. You can use any working interface script on CUPS too. Just install the printer with the -i option:

root# lpadmin -p pclprinter -v socket://11.12.13.14:9100 \
  -i /path/to/interface-script

Interface scripts might be the “unknown animal” to many. However, with CUPS they provide the easiest way to plug in your own custom-written filtering script or program into one specific print queue (some information about the traditional usage of interface scripts is to be found at http://playground.sun.com/printing/documentation/interface.html).

Network Printing (Purely Windows)

Network printing covers a lot of ground. To understand what exactly goes on with Samba when it is printing on behalf of its Windows clients, let's first look at a “purely Windows” setup: Windows clients with a Windows NT print server.

From Windows Clients to an NT Print Server

Windows clients printing to an NT-based print server have two options. They may:

  • Execute the driver locally and render the GDI output (EMF) into the printer-specific format on their own.

  • Send the GDI output (EMF) to the server, where the driver is executed to render the printer specific output.

Both print paths are shown in the flowcharts Print driver execution on the client and Print driver execution on the server.

Driver Execution on the Client

In the first case the print server must spool the file as raw, meaning it shouldn't touch the jobfile and try to convert it in any way. This is what a traditional UNIX-based print server can do too, and at a better performance and more reliably than an NT print server. This is what most Samba administrators probably are familiar with. One advantage of this setup is that this “spooling-only” print server may be used even if no driver(s) for UNIX are available it is sufficient to have the Windows client drivers available; and installed on the clients.

Figure 21.13. Print driver execution on the client.

Print driver execution on the client.

Driver Execution on the Server

The other path executes the printer driver on the server. The client transfers print files in EMF format to the server. The server uses the PostScript, PCL, ESC/P or other driver to convert the EMF file into the printer-specific language. It is not possible for UNIX to do the same. Currently, there is no program or method to convert a Windows client's GDI output on a UNIX server into something a printer could understand.

Figure 21.14. Print driver execution on the server.

Print driver execution on the server.

However, there is something similar possible with CUPS. Read on.

Network Printing (Windows Clients UNIX/Samba Print Servers)

Since UNIX print servers cannot execute the Win32 program code on their platform, the picture is somewhat different. However, this does not limit your options all that much. On the contrary, you may have a way here to implement printing features that are not possible otherwise.

From Windows Clients to a CUPS/Samba Print Server

Here is a simple recipe showing how you can take advantage of CUPS' powerful features for the benefit of your Windows network printing clients:

  • Let the Windows clients send PostScript to the CUPS server.

  • Let the CUPS server render the PostScript into device-specific raster format.

This requires the clients to use a PostScript driver (even if the printer is a non-PostScript model. It also requires that you have a driver on the CUPS server.

First, to enable CUPS-based printing through Samba the following options should be set in your smb.conf file [global] section:

printing = cups
printcap = cups

When these parameters are specified, all manually set print directives (like print command, or lppause command) in smb.conf (as well as in Samba itself) will be ignored. Instead, Samba will directly interface with CUPS through its application program interface (API), as long as Samba has been compiled with CUPS library (libcups) support. If Samba has not been compiled with CUPS support, and if no other print commands are set up, then printing will use the System V AT&T command set, with the -oraw option automatically passing through (if you want your own defined print commands to work with a Samba that has CUPS support compiled in, simply use printing = sysv).

Figure 21.15. Printing via CUPS/Samba server.

Printing via CUPS/Samba server.

Samba Receiving Job-files and Passing Them to CUPS

Samba must use its own spool directory (it is set by a line similar to path = /var/spool/samba, in the [printers] or [printername] section of smb.conf). Samba receives the job in its own spool space and passes it into the spool directory of CUPS (the CUPS spooling directory is set by the RequestRoot directive, in a line that defaults to RequestRoot /var/spool/cups). CUPS checks the access rights of its spool dir and resets it to healthy values with every restart. We have seen quite a few people who had used a common spooling space for Samba and CUPS, and were struggling for weeks with this “problem.

A Windows user authenticates only to Samba (by whatever means is configured). If Samba runs on the same host as CUPS, you only need to allow “localhost” to print. If they run on different machines, you need to make sure the Samba host gets access to printing on CUPS.

Network PostScript RIP

This section discusses the use of CUPS filters on the server configuration where clients make use of a PostScript driver with CUPS-PPDs.

PPDs can control all print device options. They are usually provided by the manufacturer, if you own a PostScript printer, that is. PPD files (PostScript Printer Descriptions) are always a component of PostScript printer drivers on MS Windows or Apple Mac OS systems. They are ASCII files containing user-selectable print options, mapped to appropriate PostScript, PCL or PJL commands for the target printer. Printer driver GUI dialogs translate these options “on-the-fly” into buttons and drop-down lists for the user to select.

CUPS can load, without any conversions, the PPD file from any Windows (NT is recommended) PostScript driver and handle the options. There is a Web browser interface to the print options (select http://localhost:631/printers/ and click on one Configure Printer button to see it), or a command line interface (see man lpoptions or see if you have lphelp on your system). There are also some different GUI front-ends on Linux/UNIX, which can present PPD options to users. PPD options are normally meant to be evaluated by the PostScript RIP on the real PostScript printer.

PPDs for Non-PS Printers on UNIX

CUPS does not limit itself to “real” PostScript printers in its usage of PPDs. The CUPS developers have extended the scope of the PPD concept to also describe available device and driver options for non-PostScript printers through CUPS-PPDs.

This is logical, as CUPS includes a fully featured PostScript interpreter (RIP). This RIP is based on Ghostscript. It can process all received PostScript (and additionally many other file formats) from clients. All CUPS-PPDs geared to non-PostScript printers contain an additional line, starting with the keyword *cupsFilter. This line tells the CUPS print system which printer-specific filter to use for the interpretation of the supplied PostScript. Thus CUPS lets all its printers appear as PostScript devices to its clients, because it can act as a PostScript RIP for those printers, processing the received PostScript code into a proper raster print format.

PPDs for Non-PS Printers on Windows

CUPS-PPDs can also be used on Windows-Clients, on top of a “core” PostScript driver (now recommended is the "CUPS PostScript Driver for Windows NT/200x/XP"; you can also use the Adobe one, with limitations). This feature enables CUPS to do a few tricks no other spooler can do:

  • Act as a networked PostScript RIP (Raster Image Processor), handling print files from all client platforms in a uniform way.

  • Act as a central accounting and billing server, since all files are passed through the pstops filter and are, therefore, logged in the CUPS page_log file. Note: this cannot happen with “raw” print jobs, which always remain unfiltered per definition.

  • Enable clients to consolidate on a single PostScript driver, even for many different target printers.

Using CUPS PPDs on Windows clients enables these to control all print job settings just as a UNIX client can do.

Windows Terminal Servers (WTS) as CUPS Clients

This setup may be of special interest to people experiencing major problems in WTS environments. WTS often need a multitude of non-PostScript drivers installed to run their clients' variety of different printer models. This often imposes the price of much increased instability.

Printer Drivers Running in “Kernel Mode” Cause Many Problems

In Windows NT printer drivers which run in “Kernel Mode”, introduces a high risk for the stability of the system