## The Basics

The PPD compiler, `ppdc(1)`, is a simple command-line tool that takes a single driver information file, which by convention uses the extension .drv, and produces one or more PPD files that may be distributed with your printer drivers for use with CUPS. For example, you would run the following command to create the English language PPD files defined by the driver information file mydrivers.drv:

    ppdc mydrivers.drv

The PPD files are placed in a subdirectory called ppd. The `-d` option is used to put the PPD files in a different location, for example:

    ppdc -d myppds mydrivers.drv

places the PPD files in a subdirectory named myppds. Finally, use the `-l` option to specify the language localization for the PPD files that are created, for example:

    ppdc -d myppds/de -l de mydrivers.drv
    ppdc -d myppds/en -l en mydrivers.drv
    ppdc -d myppds/es -l es mydrivers.drv
    ppdc -d myppds/fr -l fr mydrivers.drv
    ppdc -d myppds/it -l it mydrivers.drv

creates PPD files in German (de), English (en), Spanish (es), French (fr), and Italian (it) in the corresponding subdirectories. Specify multiple languages (separated by commas) to produce "globalized" PPD files:

    ppdc -d myppds -l de,en,es,fr,it mydrivers.drv

## Driver Information Files

The driver information files accepted by the PPD compiler are plain text files that define the various attributes and options that are included in the PPD files that are generated. A driver information file can define the information for one or more printers and their corresponding PPD files.

Listing 1: "examples/minimum.drv"

    // Include standard font and media definitions
    #include <font.defs>
    #include <media.defs>

    // List the fonts that are supported, in this case all standard fonts...
    Font *

    // Manufacturer, model name, and version
    Manufacturer "Foo"
    ModelName "FooJet 2000"
    Version 1.0

    // Each filter provided by the driver...
    Filter application/vnd.cups-raster 100 rastertofoo

    // Supported page sizes
    *MediaSize Letter
    MediaSize A4

    // Supported resolutions
    *Resolution k 8 0 0 0 "600dpi/600 DPI"

    // Specify the name of the PPD file we want to generate...
    PCFileName "foojet2k.ppd"

### A Simple Example

The example in Listing 1 shows a driver information file which defines the minimum required attributes to provide a valid PPD file. The first part of the file includes standard definition files for fonts and media sizes:

    #include <font.defs>
    #include <media.defs>

The `#include` directive works just like the C/C++ include directive; files included using the angle brackets (`<filename>`) are found in any of the standard include directories and files included using quotes (`"filename"`) are found in the same directory as the source or include file. The `<font.defs>` include file defines the standard fonts which are included with GPL Ghostscript and the Apple PDF RIP, while the `<media.defs>` include file defines the standard media sizes listed in Appendix B of the Adobe PostScript Printer Description File Format Specification.

CUPS provides several other standard include files:

- `<epson.h>` - Defines all of the rastertoepson driver constants.
- `<escp.h>` - Defines all of the rastertoescpx driver constants.
- `<hp.h>` - Defines all of the rastertohp driver constants.
- `<label.h>` - Defines all of the rastertolabel driver constants.
- `<pcl.h>` - Defines all of the rastertopclx driver constants.
- `<raster.defs>` - Defines all of the CUPS raster format constants.

Next we list all of the fonts that are available in the driver; for CUPS raster drivers, the following line is all that is usually supplied:

    Font *

The `Font` directive specifies the name of a single font or the asterisk to specify all fonts. For example, you would use the following line to define an additional bar code font that you are supplying with your printer driver:

    //   name         encoding  version  charset  status
    Font Barcode-Foo  Special   "(1.0)"  Special  ROM

The name of the font is `Barcode-Foo`. Since it is not a standard text font, the encoding and charset name `Special` is used. The version number is `1.0` and the status (where the font is located) is `ROM` to indicate that the font does not need to be embedded in documents that use the font for this printer.

Third comes the manufacturer, model name, and version number information strings:

    Manufacturer "Foo"
    ModelName "FooJet 2000"
    Version 1.0

These strings are used when the user (or auto-configuration program) selects the printer driver for a newly connected device.

The list of filters comes after the information strings; for the example in Listing 1, we have a single filter that takes CUPS raster data:

    Filter application/vnd.cups-raster 100 rastertofoo

Each filter specified in the driver information file is the equivalent of a printer driver for that format; if a user submits a print job in a different format, CUPS figures out the sequence of commands that will produce a supported format for the least relative cost.

Once we have defined the driver information we specify the supported options. For the example driver we support a single resolution of 600 dots per inch and two media sizes, A4 and Letter:

    *MediaSize Letter
    MediaSize A4

    *Resolution k 8 0 0 0 "600dpi/600 DPI"

The asterisk in front of the `MediaSize` and `Resolution` directives specify that those option choices are the default. The `MediaSize` directive is followed by a media size name which is normally defined in the `<media.defs>` file and corresponds to a standard Adobe media size name. If the default media size is `Letter`, the PPD compiler will override it to be `A4` for non-English localizations for you automatically.

The `Resolution` directive accepts several values after it as follows:

1. Colorspace for this resolution, if any. In the example file, the colorspace `k` is used which corresponds to black. For printer drivers that support color printing, this field is usually specified as "-" for "no change".
2. Bits per color. In the example file, we define 8 bits per color, for a continuous-tone grayscale output. All versions of CUPS support 1 and 8 bits per color. CUPS 1.2 and higher (OS X 10.5 and higher) also supports 16 bits per color.
3. Rows per band. In the example file, we define 0 rows per band to indicate that our printer driver does not process the page in bands.
4. Row feed. In the example, we define the feed value to be 0 to indicate that our printer driver does not interleave the output.
5. Row step. In the example, we define the step value to be 0 to indicate that our printer driver does not interleave the output. This value normally indicates the spacing between the nozzles of an inkjet printer - when combined with the previous two values, it informs the driver how to stagger the output on the page to produce interleaved lines on the page for higher-resolution output.
6. Choice name and text. In the example, we define the choice name and text to be `"600dpi/600 DPI"`. The name and text are separated by slash (`/`) character; if no text is specified, then the name is used as the text. The PPD compiler parses the name to determine the actual resolution; the name can be of the form `RESOLUTIONdpi` for resolutions that are equal horizontally and vertically or `HRESxVRESdpi` for isometric resolutions. Only integer resolution values are supported, so a resolution name of `300dpi` is valid while `300.1dpi` is not.

Finally, the `PCFileName` directive specifies that the named PPD file should be written for the current driver definitions:

    PCFileName "foojet2k.ppd"

The filename follows the directive and must conform to the Adobe filename requirements in the Adobe Postscript Printer Description File Format Specification. Specifically, the filename may not exceed 8 characters followed by the extension .ppd. The `FileName` directive can be used to specify longer filenames:

    FileName "FooJet 2000"

### Grouping and Inheritance

The previous example created a single PPD file. Driver information files can also define multiple printers by using the PPD compiler grouping functionality. Directives are grouped using the curly braces (`{` and `}`) and every group that uses the `PCFileName` or `FileName` directives produces a PPD file with that name. Listing 2 shows a variation of the original example that uses two groups to define two printers that share the same printer driver filter but provide two different resolution options.

Listing 2: "examples/grouping.drv"

    // Include standard font and media definitions
    #include <font.defs>
    #include <media.defs>

    // List the fonts that are supported, in this case all standard fonts...
    Font *

    // Manufacturer and version
    Manufacturer "Foo"
    Version 1.0

    // Each filter provided by the driver...
    Filter application/vnd.cups-raster 100 rastertofoo

    // Supported page sizes
    *MediaSize Letter
    MediaSize A4

    {
      // Supported resolutions
      *Resolution k 8 0 0 0 "600dpi/600 DPI"

      // Specify the model name and filename...
      ModelName "FooJet 2000"
      PCFileName "foojet2k.ppd"
    }

    {
      // Supported resolutions
      *Resolution k 8 0 0 0 "1200dpi/1200 DPI"

      // Specify the model name and filename...
      ModelName "FooJet 2001"
      PCFileName "foojt2k1.ppd"
    }

The second example is essentially the same as the first, except that each printer model is defined inside of a pair of curly braces. For example, the first printer is defined using:

    {
      // Supported resolutions
      *Resolution k 8 0 0 0 "600dpi/600 DPI"

      // Specify the model name and filename...
      ModelName "FooJet 2000"
      PCFileName "foojet2k.ppd"
    }

The printer inherits all of the definitions from the parent group (the top part of the file) and adds the additional definitions inside the curly braces for that printer driver. When we define the second group, it also inherits the same definitions from the parent group but none of the definitions from the first driver. Groups can be nested to any number of levels to support variations of similar models without duplication of information.

### Color Support

For printer drivers that support color printing, the `ColorDevice` and `ColorModel` directives should be used to tell the printing system that color output is desired and in what formats. Listing 3 shows a variation of the previous example which includes a color printer that supports printing at 300 and 600 DPI.

The key changes are the addition of the `ColorDevice` directive:

    ColorDevice true

which tells the printing system that the printer supports color printing, and the `ColorModel` directives:

    ColorModel Gray/Grayscale w chunky 0
    *ColorModel RGB/Color rgb chunky 0

which tell the printing system which colorspaces are supported by the printer driver for color printing. Each of the `ColorModel` directives is followed by the option name and text (`Gray/Grayscale` and `RGB/Color`), the colorspace name (`w` and `rgb`), the color organization (`chunky`), and the compression mode number (`0`) to be passed to the driver. The option name can be any of the standard Adobe `ColorModel` names:

- `Gray` - Grayscale output.
- `RGB` - Color output, typically using the RGB colorspace, but without a separate black channel.
- `CMYK` - Color output with a separate black channel.

Custom names can be used, however it is recommended that you use your vendor prefix for any custom names, for example "fooName".

The colorspace name can be any of the following universally supported colorspaces:

- `w` - Luminance
- `rgb` - Red, green, blue
- `k` - Black
- `cmy` - Cyan, magenta, yellow
- `cmyk` - Cyan, magenta, yellow, black

The color organization can be any of the following values:

- `chunky` - Color values are passed together on a line as RGB RGB RGB RGB
- `banded` - Color values are passed separately on a line as RRRR GGGG BBBB; not supported by the Apple RIP filters
- `planar` - Color values are passed separately on a page as RRRR RRRR RRRR ... GGGG GGGG GGGG ... BBBB BBBB BBBB; not supported by the Apple RIP filters

The compression mode value is passed to the driver in the `cupsCompression` attribute. It is traditionally used to select an appropriate compression mode for the color model but can be used for any purpose, such as specifying a photo mode vs. standard mode.

Listing 3: "examples/color.drv"

    // Include standard font and media definitions
    #include <font.defs>
    #include <media.defs>

    // List the fonts that are supported, in this case all standard fonts...
    Font *

    // Manufacturer and version
    Manufacturer "Foo"
    Version 1.0

    // Each filter provided by the driver...
    Filter application/vnd.cups-raster 100 rastertofoo

    // Supported page sizes
    *MediaSize Letter
    MediaSize A4

    {
      // Supported resolutions
      *Resolution k 8 0 0 0 "600dpi/600 DPI"

      // Specify the model name and filename...
      ModelName "FooJet 2000"
      PCFileName "foojet2k.ppd"
    }

    {
      // Supports color printing
      ColorDevice true

      // Supported colorspaces
      ColorModel Gray/Grayscale w chunky 0
      *ColorModel RGB/Color rgb chunky 0

      // Supported resolutions
      *Resolution - 8 0 0 0 "300dpi/300 DPI"
      Resolution - 8 0 0 0 "600dpi/600 DPI"

      // Specify the model name and filename...
      ModelName "FooJet Color"
      PCFileName "foojetco.ppd"
    }

### Defining Custom Options and Option Groups

The `Group`, `Option`, and `Choice` directives are used to define or select a group, option, or choice. Listing 4 shows a variation of the first example that provides two custom options in a group named "Footasm".

Listing 4: "examples/custom.drv"

    // Include standard font and media definitions
    #include <font.defs>
    #include <media.defs>

    // List the fonts that are supported, in this case all standard fonts...
    Font *

    // Manufacturer, model name, and version
    Manufacturer "Foo"
    ModelName "FooJet 2000"
    Version 1.0

    // Each filter provided by the driver...
    Filter application/vnd.cups-raster 100 rastertofoo

    // Supported page sizes
    *MediaSize Letter
    MediaSize A4

    // Supported resolutions
    *Resolution k 8 0 0 0 "600dpi/600 DPI"

    // Option Group
    Group "Footasm"

      // Boolean option
      Option "fooEnhance/Resolution Enhancement" Boolean AnySetup 10
        *Choice True/Yes "<</cupsCompression 1>>setpagedevice"
        Choice False/No "<</cupsCompression 0>>setpagedevice"

      // Multiple choice option
      Option "fooOutputType/Output Quality" PickOne AnySetup 10
        *Choice "Auto/Automatic Selection"
                "<</OutputType(Auto)>>setpagedevice""
        Choice "Text/Optimize for Text"
                "<</OutputType(Text)>>setpagedevice""
        Choice "Graph/Optimize for Graphics"
                "<</OutputType(Graph)>>setpagedevice""
        Choice "Photo/Optimize for Photos"
                "<</OutputType(Photo)>>setpagedevice""

    // Specify the name of the PPD file we want to generate...
    PCFileName "foojet2k.ppd"

The custom group is introduced by the `Group` directive which is followed by the name and optionally text for the user:

    Group "Footasm/Footastic Options"

The group name must conform to the PPD specification and cannot exceed 40 characters in length. If you specify user text, it cannot exceed 80 characters in length. The groups `General`, `Extra`, and `InstallableOptions` are predefined by CUPS; the general and extra groups are filled by the UI options defined by the PPD specification. The `InstallableOptions` group is reserved for options that define whether accessories for the printer (duplexer unit, finisher, stapler, etc.) are installed.

Once the group is specified, the `Option` directive is used to introduce a new option:

    Option "fooEnhance/Resolution Enhancement" Boolean AnySetup 10

The directive is followed by the name of the option and any optional user text, the option type, the PostScript document group, and the sort order number. The option name must conform to the PPD specification and cannot exceed 40 characters in length. If you specify user text, it cannot exceed 80 characters in length.

The option type can be `Boolean` for true/false selections, `PickOne` for picking one of many choices, or `PickMany` for picking zero or more choices. Boolean options can have at most two choices with the names `False` and `True`. Pick options can have any number of choices, although for Windows compatibility reasons the number of choices should not exceed 255.

The PostScript document group is typically `AnySetup`, meaning that the option can be introduced at any point in the PostScript document. Other values include `PageSetup` to include the option before each page and `DocumentSetup` to include the option once at the beginning of the document.

The sort order number is used to sort the printer commands associated with each option choice within the PostScript document. This allows you to setup certain options before others as required by the printer. For most CUPS raster printer drivers, the value `10` can be used for all options.

Once the option is specified, each option choice can be listed using the `Choice` directive:

    *Choice True/Yes "<</cupsCompression 1>>setpagedevice"
    Choice False/No "<</cupsCompression 0>>setpagedevice"

The directive is followed by the choice name and optionally user text, and the PostScript commands that should be inserted when printing a file to this printer. The option name must conform to the PPD specification and cannot exceed 40 characters in length. If you specify user text, it cannot exceed 80 characters in length.

The PostScript commands are also interpreted by any RIP filters, so these commands typically must be present for all option choices. Most commands take the form:

    <</name value>>setpagedevice

where `name` is the name of the PostScript page device attribute and `value` is the numeric or string value for that attribute.

### Defining Constants

Sometimes you will want to define constants for your drivers so that you can share values in different groups within the same driver information file, or to share values between different driver information files using the `#include` directive. The `#define` directive is used to define constants for use in your printer definitions:

    #define NAME value

The `NAME` is any sequence of letters, numbers, and the underscore. The `value` is a number or string; if the value contains spaces you must put double quotes around it, for example:

    #define FOO "My String Value"

Constants can also be defined on the command-line using the `-D` option:

    ppdc -DNAME="value" filename.drv

Once defined, you use the notation `$NAME` to substitute the value of the constant in the file, for example:

    #define MANUFACTURER "Foo"
    #define FOO_600      0
    #define FOO_1200     1

    {
      Manufacturer "$MANUFACTURER"
      ModelNumber $FOO_600
      ModelName "FooJet 2000"
      ...
    }

    {
      Manufacturer "$MANUFACTURER"
      ModelNumber $FOO_1200
      ModelName "FooJet 2001"
      ...
    }

Numeric constants can be bitwise OR'd together by placing the constants inside parenthesis, for example:

    // ModelNumber capability bits
    #define DUPLEX 1
    #define COLOR  2

    ...

    {
      // Define a model number specifying the capabilities of the printer...
      ModelNumber ($DUPLEX $COLOR)
      ...
    }

### Conditional Statements

The PPD compiler supports conditional compilation using the `#if`, `#elif`, `#else`, and `#endif` directives. The `#if` and `#elif` directives are followed by a constant name or an expression. For example, to include a group of options when "ADVANCED" is defined:

    #if ADVANCED
    Group "Advanced/Advanced Options"
      Option "fooCyanAdjust/Cyan Adjustment"
        Choice "plus10/+10%" ""
        Choice "plus5/+5%" ""
        *Choice "none/No Adjustment" ""
        Choice "minus5/-5%" ""
        Choice "minus10/-10%" ""
      Option "fooMagentaAdjust/Magenta Adjustment"
        Choice "plus10/+10%" ""
        Choice "plus5/+5%" ""
        *Choice "none/No Adjustment" ""
        Choice "minus5/-5%" ""
        Choice "minus10/-10%" ""
      Option "fooYellowAdjust/Yellow Adjustment"
        Choice "plus10/+10%" ""
        Choice "plus5/+5%" ""
        *Choice "none/No Adjustment" ""
        Choice "minus5/-5%" ""
        Choice "minus10/-10%" ""
      Option "fooBlackAdjust/Black Adjustment"
        Choice "plus10/+10%" ""
        Choice "plus5/+5%" ""
        *Choice "none/No Adjustment" ""
        Choice "minus5/-5%" ""
        Choice "minus10/-10%" ""
    #endif

### Defining Constraints

Constraints are strings that are used to specify that one or more option choices are incompatible, for example two-sided printing on transparency media. Constraints are also used to prevent the use of uninstalled features such as the duplexer unit, additional media trays, and so forth.

The `UIConstraints` directive is used to specify a constraint that is placed in the PPD file. The directive is followed by a string using one of the following formats:

    UIConstraints "*Option1 *Option2"
    UIConstraints "*Option1 Choice1 *Option2"
    UIConstraints "*Option1 *Option2 Choice2"
    UIConstraints "*Option1 Choice1 *Option2 Choice2"

Each option name is preceded by the asterisk (`*`). If no choice is given for an option, then all choices except `False` and `None` will conflict with the other option and choice(s). Since the PPD compiler automatically adds reciprocal constraints (option A conflicts with option B, so therefore option B conflicts with option A), you need only specify the constraint once.

Listing 5: "examples/constraint.drv"

    // Include standard font and media definitions
    #include <font.defs>
    #include <media.defs>

    // List the fonts that are supported, in this case all standard fonts...
    Font *

    // Manufacturer, model name, and version
    Manufacturer "Foo"
    ModelName "FooJet 2000"
    Version 1.0

    // Each filter provided by the driver...
    Filter application/vnd.cups-raster 100 rastertofoo

    // Supported page sizes
    *MediaSize Letter
    MediaSize A4

    // Supported resolutions
    *Resolution k 8 0 0 0 "600dpi/600 DPI"

    // Installable Option Group
    Group "InstallableOptions/Options Installed"

      // Duplexing unit option
      Option "OptionDuplexer/Duplexing Unit" Boolean AnySetup 10
        Choice True/Installed ""
        *Choice "False/Not Installed" ""

    // General Option Group
    Group General

      // Duplexing option
      Option "Duplex/Two-Sided Printing" PickOne AnySetup 10
        *Choice "None/No" "<</Duplex false>>setpagedevice""
        Choice "DuplexNoTumble/Long Edge Binding"
               "<</Duplex true/Tumble false>>setpagedevice""
        Choice "DuplexTumble/Short Edge Binding"
               "<</Duplex true/Tumble true>>setpagedevice""

    // Only allow duplexing if the duplexer is installed
    UIConstraints "*Duplex *OptionDuplexer False"

    // Specify the name of the PPD file we want to generate...
    PCFileName "foojet2k.ppd"

Listing 5 shows a variation of the first example with an added `Duplex` option and installable option for the duplexer, `OptionDuplex`. A constraint is added at the end to specify that any choice of the `Duplex` option that is not `None` is incompatible with the "Duplexer Installed" option set to "Not Installed" (`False`):

    UIConstraints "*Duplex *OptionDuplexer False"

#### Enhanced Constraints

CUPS 1.4 supports constraints between 2 or more options using the `Attribute` directive. `cupsUIConstraints` attributes define the constraints, while `cupsUIResolver` attributes define option changes to resolve constraints. For example, we can specify the previous duplex constraint with a resolver that turns off duplexing with the following two lines:

    Attribute cupsUIConstraints DuplexOff "*Duplex *OptionDuplexer False"
    Attribute cupsUIResolver DuplexOff "*Duplex None"

## Localization

The PPD compiler provides localization of PPD files in different languages through message catalog files in the GNU gettext or Apple .strings formats. Each user text string and several key PPD attribute values such as `LanguageVersion` and `LanguageEncoding` are looked up in the corresponding message catalog and the translated text is substituted in the generated PPD files. One message catalog file can be used by multiple driver information files, and each file contains a single language translation.

### The ppdpo Utility

While CUPS includes localizations of all standard media sizes and options in several languages, your driver information files may provide their own media sizes and options that need to be localized. CUPS provides a utility program to aid in the localization of drivers called `ppdpo(1)`. The `ppdpo` program creates or updates a message catalog file based upon one or more driver information files. New messages are added with the word "TRANSLATE" added to the front of the translation string to make locating new strings for translation easier. The program accepts the message catalog filename and one or more driver information files.

For example, run the following command to create a new German message catalog called de.po for all of the driver information files in the current directory:

    ppdpo -o de.po *.drv

If the file de.po already exists, `ppdpo` will update the contents of the file with any new messages that need to be translated. To create an Apple .strings file instead, specify the output filename with a .strings extension, for example:

    ppdpo -o de.strings *.drv

### Using Message Catalogs with the PPD Compiler

Once you have created a message catalog, use the `#po` directive to declare it in each driver information file. For example, to declare the German message catalog for a driver use:

    #po de "de.po"  // German

In fact, you can use the `#po` directive as many times as needed:

    #po de "de.po"  // German
    #po es "es.po"  // Spanish
    #po fr "fr.po"  // French
    #po it "it.po"  // Italian
    #po ja "ja.po"  // Japanese

The filename ("de.po", etc.) can be relative to the location of the driver information file or an absolute path. Once defined, the PPD compiler will automatically generate a globalized PPD for every language declared in your driver information file. To generate a single-language PPD file, simply use the `-l` option to list the corresponding locale, for example:

    ppdc -l de -d ppd/de mydrivers.drv

to generate German PPD files.