Back to CUPS 1.5 Documents
The CUPS PPD API provides read-only access the data in PostScript Printer
Description ("PPD") files which are used for all printers with a driver. With
it you can obtain the data necessary to display printer options to users, mark
option choices and check for conflicting choices, and output marked choices in
PostScript output. The
ppd_file_t
structure contains all of the information in a PPD file.
Note:
The CUPS PPD API uses the terms "option" and "choice" instead of the Adobe terms "MainKeyword" and "OptionKeyword" to refer to specific printer options and features. CUPS also treats option ("MainKeyword") and choice ("OptionKeyword") values as case-insensitive strings, so option "InputSlot" and choice "Upper" are equivalent to "inputslot" and "upper", respectively.
The
ppdOpenFile function "opens" a
PPD file and loads it into memory. For example, the following code opens the
current printer's PPD file in a CUPS filter:
#include <cups/ppd.h> ppd_file_t *ppd = ppdOpenFile(getenv("PPD"));
The return value is a pointer to a new
ppd_file_t structure or
NULL
if the PPD file does not exist or cannot be loaded. The
ppdClose function frees the memory used
by the structure:
#include <cups/ppd.h> ppd_file_t *ppd; ppdClose(ppd);
Once closed, pointers to the
ppd_file_t
structure and any data in it will no longer be valid.
PPD files support multiple options, which are stored in arrays of
ppd_option_t and
ppd_choice_t structures.
Each option in turn is associated with a group stored in a
ppd_group_t structure. Groups can be
specified in the PPD file; if an option is not associated with a group
then it is put in an automatically-generated "General" group. Groups can also
have sub-groups, however CUPS currently ignores sub-groups because of past
abuses of this functionality.
Option choices are selected by marking them using one of three functions. The
first is
ppdMarkDefaults which
selects all of the default options in the PPD file:
#include <cups/ppd.h> ppd_file_t *ppd; ppdMarkDefaults(ppd);
The second is
ppdMarkOption
which selects a single option choice in the PPD file. For example, the following
code selects the upper paper tray:
#include <cups/ppd.h> ppd_file_t *ppd; ppdMarkOption(ppd, "InputSlot", "Upper");
The last function is
cupsMarkOptions which selects
multiple option choices in the PPD file from an array of CUPS options, mapping
IPP attributes like "media" and "sides" to their corresponding PPD options. You
typically use this function in a print filter with
cupsParseOptions and
ppdMarkDefaults to select all of
the option choices needed for the job, for example:
#include <cups/ppd.h> ppd_file_t *ppd = ppdOpenFile(getenv("PPD")); cups_option_t *options = NULL; int num_options = cupsParseOptions(argv[5], 0, &options); ppdMarkDefaults(ppd); cupsMarkOptions(ppd, num_options, options); cupsFreeOptions(num_options, options);
PPD files support specification of conflict conditions, called
constraints, between different options. Constraints are stored in an array of
ppd_const_t structures which specify
the options and choices that conflict with each other. The
ppdConflicts function tells you
how many of the selected options are incompatible. Since constraints are
normally specified in pairs, the returned value is typically an even number.
Page sizes are special options which have physical dimensions and margins
associated with them. The size information is stored in
ppd_size_t structures and is available
by looking up the named size with the
ppdPageSize function. The page size and
margins are returned in units called points; there are 72 points per inch. If
you pass
NULL for the size, the currently selected size is
returned:
#include <cups/ppd.h> ppd_file_t *ppd; ppd_size_t *size = ppdPageSize(ppd, NULL);
Besides the standard page sizes listed in a PPD file, some printers
support variable or custom page sizes. Custom page sizes are supported if the
variables_sizes member of the
ppd_file_t structure is non-zero.
The
custom_min,
custom_max, and
custom_margins members of the
ppd_file_t structure define the limits
of the printable area. To get the resulting media size, use a page size string
of the form "Custom.widthxlength", where "width" and "length" are
in points. Custom page size names can also be specified in inches
("Custom.widthxheightin"), centimeters
("Custom.widthxheightcm"), or millimeters
("Custom.widthxheightmm"):
#include <cups/ppd.h> ppd_file_t *ppd; /* Get an 576x720 point custom page size */ ppd_size_t *size = ppdPageSize(ppd, "Custom.576x720"); /* Get an 8x10 inch custom page size */ ppd_size_t *size = ppdPageSize(ppd, "Custom.8x10in"); /* Get a 100x200 millimeter custom page size */ ppd_size_t *size = ppdPageSize(ppd, "Custom.100x200mm"); /* Get a 12.7x34.5 centimeter custom page size */ ppd_size_t *size = ppdPageSize(ppd, "Custom.12.7x34.5cm");
If the PPD does not support variable page sizes, the
ppdPageSize function will return
NULL.
Every PPD file is composed of one or more attributes. Most of these attributes are used to define groups, options, choices, and page sizes, however several informational attributes may be present which you can access in your program or filter. Attributes normally look like one of the following examples in a PPD file:
*name: "value" *name spec: "value" *name spec/text: "value"
The
ppdFindAttr and
ppdFindNextAttr functions find the
first and next instances, respectively, of the named attribute with the given
"spec" string and return a
ppd_attr_t
structure. If you provide a NULL specifier string, all attributes with the
given name will be returned. For example, the following code lists all of the
Product attributes in a PPD file:
#include <cups/ppd.h> ppd_file_t *ppd; ppd_attr_t *attr; for (attr = ppdFindAttr(ppd, "Product", NULL); attr != NULL; attr = ppdFindNextAttr(ppd, "Product", NULL)) puts(attr->value);
Get a list of conflicting options in a marked PPD.
int cupsGetConflicts (
ppd_file_t *ppd,
const char *option,
const char *choice,
cups_option_t **options
);
Number of conflicting options
This function gets a list of options that would conflict if "option" and
"choice" were marked in the PPD. You would typically call this function
after marking the currently selected options in the PPD in order to
determine whether a new option selection would cause a conflict.
The number of conflicting options are returned with "options" pointing to the conflicting options. The returned option array must be freed using
cupsFreeOptions.
Mark command-line options in a PPD file.
int cupsMarkOptions (
ppd_file_t *ppd,
int num_options,
cups_option_t *options
);
1 if conflicts exist, 0 otherwise
This function maps the IPP "finishings", "media", "mirror", "multiple-document-handling", "output-bin", "print-color-mode", "print-quality", "printer-resolution", and "sides" attributes to their corresponding PPD options and choices.
Resolve conflicts in a marked PPD.
int cupsResolveConflicts (
ppd_file_t *ppd,
const char *option,
const char *choice,
int *num_options,
cups_option_t **options
);
NULLfor none
NULLfor none
1 on success, 0 on failure
This function attempts to resolve any conflicts in a marked PPD, returning
a list of option changes that are required to resolve them. On input,
"num_options" and "options" contain any pending option changes that have
not yet been marked, while "option" and "choice" contain the most recent
selection which may or may not be in "num_options" or "options".
On successful return, "num_options" and "options" are updated to contain "option" and "choice" along with any changes required to resolve conflicts specified in the PPD file and 1 is returned.
If option conflicts cannot be resolved, "num_options" and "options" are not changed and 0 is returned.
When resolving conflicts,
cupsResolveConflicts does not consider
changes to the current page size (
media,
PageSize, and
PageRegion) or to the most recent option specified in "option".
Thus, if the only way to resolve a conflict is to change the page size
or the option the user most recently changed,
cupsResolveConflicts
will return 0 to indicate it was unable to resolve the conflicts.
The
cupsResolveConflicts function uses one of two sources of option
constraint information. The preferred constraint information is defined by
cupsUIConstraints and
cupsUIResolver attributes - in this
case, the PPD file provides constraint resolution actions.
The backup constraint information is defined by the
UIConstraints and
NonUIConstraints attributes. These
constraints are resolved algorithmically by first selecting the default
choice for the conflicting option, then iterating over all possible choices
until a non-conflicting option choice is found.
Free all memory used by the PPD file.
void ppdClose (
ppd_file_t *ppd
);
Collect all marked options that reside in the specified section.
int ppdCollect (
ppd_file_t *ppd,
ppd_section_t section,
ppd_choice_t ***choices
);
Number of options marked
The choices array should be freed using
free when you are
finished with it.
Collect all marked options that reside in the specified section and minimum order.
int ppdCollect2 (
ppd_file_t *ppd,
ppd_section_t section,
float min_order,
ppd_choice_t ***choices
);
Number of options marked
The choices array should be freed using
free when you are
finished with it.
Check to see if there are any conflicts among the marked option choices.
int ppdConflicts (
ppd_file_t *ppd
);
Number of conflicts found
The returned value is the same as returned by
ppdMarkOption.
Emit code for marked options to a file.
int ppdEmit (
ppd_file_t *ppd,
FILE *fp,
ppd_section_t section
);
0 on success, -1 on failure
Emit a subset of the code for marked options to a file.
int ppdEmitAfterOrder (
ppd_file_t *ppd,
FILE *fp,
ppd_section_t section,
int limit,
float min_order
);
0 on success, -1 on failure
When "limit" is non-zero, this function only emits options whose
OrderDependency value is greater than or equal to "min_order".
When "limit" is zero, this function is identical to ppdEmit().
Emit code for marked options to a file.
int ppdEmitFd (
ppd_file_t *ppd,
int fd,
ppd_section_t section
);
0 on success, -1 on failure
Emit code for JCL options to a file.
int ppdEmitJCL (
ppd_file_t *ppd,
FILE *fp,
int job_id,
const char *user,
const char *title
);
0 on success, -1 on failure
Emit JCLEnd code to a file.
int ppdEmitJCLEnd (
ppd_file_t *ppd,
FILE *fp
);
0 on success, -1 on failure
Get a string containing the code for marked options.
char *ppdEmitString (
ppd_file_t *ppd,
ppd_section_t section,
float min_order
);
String containing option code or
NULL if there is no option code
When "min_order" is greater than zero, this function only includes options
whose OrderDependency value is greater than or equal to "min_order".
Otherwise, all options in the specified section are included in the
returned string.
The return string is allocated on the heap and should be freed using
free when you are done with it.
Returns the text assocated with a status.
const char *ppdErrorString (
ppd_status_t status
);
Status string
Find the first matching attribute.
ppd_attr_t *ppdFindAttr (
ppd_file_t *ppd,
const char *name,
const char *spec
);
NULL
Attribute or
NULL if not found
Return a pointer to an option choice.
ppd_choice_t *ppdFindChoice (
ppd_option_t *o,
const char *choice
);
Choice pointer or
NULL
Find a custom option.
ppd_coption_t *ppdFindCustomOption (
ppd_file_t *ppd,
const char *keyword
);
Custom option or NULL
Find a parameter for a custom option.
ppd_cparam_t *ppdFindCustomParam (
ppd_coption_t *opt,
const char *name
);
Custom parameter or NULL
Return the marked choice for the specified option.
ppd_choice_t *ppdFindMarkedChoice (
ppd_file_t *ppd,
const char *option
);
Pointer to choice or
NULL
Find the next matching attribute.
ppd_attr_t *ppdFindNextAttr (
ppd_file_t *ppd,
const char *name,
const char *spec
);
NULL
Attribute or
NULL if not found
Return a pointer to the specified option.
ppd_option_t *ppdFindOption (
ppd_file_t *ppd,
const char *option
);
Pointer to option or
NULL
Return the first parameter for a custom option.
ppd_cparam_t *ppdFirstCustomParam (
ppd_coption_t *opt
);
Custom parameter or NULL
Return the first option in the PPD file.
ppd_option_t *ppdFirstOption (
ppd_file_t *ppd
);
First option or
NULL
Options are returned from all groups in ascending alphanumeric order.
Test whether an option choice conflicts with an installable option.
int ppdInstallableConflict (
ppd_file_t *ppd,
const char *option,
const char *choice
);
1 if conflicting, 0 if not conflicting
This function tests whether a particular option choice is available based on constraints against options in the "InstallableOptions" group.
Check to see if an option is marked.
int ppdIsMarked (
ppd_file_t *ppd,
const char *option,
const char *choice
);
Non-zero if option is marked
Return the status from the last ppdOpen*().
ppd_status_t ppdLastError (
int *line
);
Status code
Localize the PPD file to the current locale.
int ppdLocalize (
ppd_file_t *ppd
);
0 on success, -1 on error
All groups, options, and choices are localized, as are ICC profile descriptions, printer presets, and custom option parameters. Each localized string uses the UTF-8 character encoding.
Localize an attribute.
ppd_attr_t *ppdLocalizeAttr (
ppd_file_t *ppd,
const char *keyword,
const char *spec
);
NULLfor none
Localized attribute or
NULL if none exists
This function uses the current locale to find the localized attribute for the given main and option keywords. If no localized version of the attribute exists for the current locale, the unlocalized version is returned.
Get the localized version of a cupsIPPReason attribute.
const char *ppdLocalizeIPPReason (
ppd_file_t *ppd,
const char *reason,
const char *scheme,
char *buffer,
size_t bufsize
);
Value or NULL if not found
This function uses the current locale to find the corresponding reason
text or URI from the attribute value. If "scheme" is NULL or "text",
the returned value contains human-readable (UTF-8) text from the translation
string or attribute value. Otherwise the corresponding URI is returned.
If no value of the requested scheme can be found, NULL is returned.
Get the localized version of a marker-names attribute value.
const char *ppdLocalizeMarkerName (
ppd_file_t *ppd,
const char *name
);
Value or
NULL if not found
This function uses the current locale to find the corresponding name
text from the attribute value. If no localized text for the requested
name can be found,
NULL is returned.
Mark all default options in the PPD file.
void ppdMarkDefaults (
ppd_file_t *ppd
);
Mark an option in a PPD file and return the number of conflicts.
int ppdMarkOption (
ppd_file_t *ppd,
const char *option,
const char *choice
);
Number of conflicts
Return the next parameter for a custom option.
ppd_cparam_t *ppdNextCustomParam (
ppd_coption_t *opt
);
Custom parameter or NULL
Return the next option in the PPD file.
ppd_option_t *ppdNextOption (
ppd_file_t *ppd
);
Next option or
NULL
Options are returned from all groups in ascending alphanumeric order.
Read a PPD file into memory.
ppd_file_t *ppdOpen (
FILE *fp
);
PPD file record
Read a PPD file into memory.
ppd_file_t *ppdOpen2 (
cups_file_t *fp
);
PPD file record or
NULL if the PPD file could not be opened.
Read a PPD file into memory.
ppd_file_t *ppdOpenFd (
int fd
);
PPD file record or
NULL if the PPD file could not be opened.
Read a PPD file into memory.
ppd_file_t *ppdOpenFile (
const char *filename
);
PPD file record or
NULL if the PPD file could not be opened.
Get the page length for the given size.
float ppdPageLength (
ppd_file_t *ppd,
const char *name
);
Length of page in points or 0.0
Get the page size record for the given size.
ppd_size_t *ppdPageSize (
ppd_file_t *ppd,
const char *name
);
Size record for page or NULL
Return the custom page size limits.
int ppdPageSizeLimits (
ppd_file_t *ppd,
ppd_size_t *minimum,
ppd_size_t *maximum
);
1 if custom sizes are supported, 0 otherwise
This function returns the minimum and maximum custom page sizes and printable
areas based on the currently-marked (selected) options.
If the specified PPD file does not support custom page sizes, both "minimum" and "maximum" are filled with zeroes.
Get the page width for the given size.
float ppdPageWidth (
ppd_file_t *ppd,
const char *name
);
Width of page in points or 0.0
Set the conformance level for PPD files.
void ppdSetConformance (
ppd_conform_t c
);
PPD Attribute Structure
typedef struct ppd_attr_s ppd_attr_t;
Option choices
typedef struct ppd_choice_s ppd_choice_t;
Conformance Levels
typedef enum ppd_conform_e ppd_conform_t;
Constraints
typedef struct ppd_const_s ppd_const_t;
Custom Option
typedef struct ppd_coption_s ppd_coption_t;
Custom Parameter
typedef struct ppd_cparam_s ppd_cparam_t;
Custom Parameter Limit
typedef union ppd_cplimit_u ppd_cplimit_t;
Custom Parameter Type
typedef enum ppd_cptype_e ppd_cptype_t;
Custom Parameter Value
typedef union ppd_cpvalue_u ppd_cpvalue_t;
Colorspaces
typedef enum ppd_cs_e ppd_cs_t;
Emulators
typedef struct ppd_emul_s ppd_emul_t;
PPD File
typedef struct ppd_file_s ppd_file_t;
Groups
typedef struct ppd_group_s ppd_group_t;
Options
typedef struct ppd_option_s ppd_option_t;
sRGB Color Profiles
typedef struct ppd_profile_s ppd_profile_t;
Order dependency sections
typedef enum ppd_section_e ppd_section_t;
Page Sizes
typedef struct ppd_size_s ppd_size_t;
Status Codes
typedef enum ppd_status_e ppd_status_t;
UI Types
typedef enum ppd_ui_e ppd_ui_t;
PPD Attribute Structure
struct ppd_attr_s {
char name[PPD_MAX_NAME];
char spec[PPD_MAX_NAME];
char text[PPD_MAX_TEXT];
char *value;
};
Option choices
struct ppd_choice_s {
char choice[PPD_MAX_NAME];
char *code;
char marked;
ppd_option_t *option;
char text[PPD_MAX_TEXT];
};
Constraints
struct ppd_const_s {
char choice1[PPD_MAX_NAME];
char choice2[PPD_MAX_NAME];
char option1[PPD_MAX_NAME];
char option2[PPD_MAX_NAME];
};
Custom Option
struct ppd_coption_s {
char keyword[PPD_MAX_NAME];
int marked;
ppd_option_t *option;
cups_array_t *params;
};
Custom Parameter
struct ppd_cparam_s {
ppd_cpvalue_t current;
ppd_cplimit_t minimum, maximum;
char name[PPD_MAX_NAME];
int order;
char text[PPD_MAX_TEXT];
ppd_cptype_t type;
};
Emulators
struct ppd_emul_s {
char name[PPD_MAX_NAME];
char *start;
char *stop;
};
PPD File
struct ppd_file_s {
int accurate_screens;
int color_device;
ppd_cs_t colorspace;
ppd_const_t *consts;
int contone_only;
float custom_margins[4];
float custom_max[2];
float custom_min[2];
ppd_emul_t *emulations;
char **filters;
int flip_duplex;
char **fonts;
ppd_group_t *groups;
char *jcl_begin;
char *jcl_end;
char *jcl_ps;
int landscape;
char *lang_encoding;
char *lang_version;
int language_level;
int manual_copies;
char *manufacturer;
int model_number;
char *modelname;
char *nickname;
int num_consts;
int num_emulations;
int num_filters;
int num_fonts;
int num_groups;
int num_profiles;
int num_sizes;
char *patches;
char *pcfilename;
char *product;
ppd_profile_t *profiles;
char *protocols;
char *shortnickname;
ppd_size_t *sizes;
int throughput;
char *ttrasterizer;
int variable_sizes;
};
Groups
struct ppd_group_s {
char text[PPD_MAX_TEXT - PPD_MAX_NAME];
char name[PPD_MAX_NAME];
int num_options;
int num_subgroups;
ppd_option_t *options;
struct ppd_group_s *subgroups;
};
Options
struct ppd_option_s {
ppd_choice_t *choices;
char conflicted;
char defchoice[PPD_MAX_NAME];
char keyword[PPD_MAX_NAME];
int num_choices;
float order;
ppd_section_t section;
char text[PPD_MAX_TEXT];
ppd_ui_t ui;
};
sRGB Color Profiles
struct ppd_profile_s {
float density;
float gamma;
float matrix[3][3];
char media_type[PPD_MAX_NAME];
char resolution[PPD_MAX_NAME];
};
Page Sizes
struct ppd_size_s {
float bottom;
float left;
float length;
int marked;
char name[PPD_MAX_NAME];
float right;
float top;
float width;
};
Custom Parameter Limit
union ppd_cplimit_u {
float custom_curve;
int custom_int;
float custom_invcurve;
int custom_passcode;
int custom_password;
float custom_points;
float custom_real;
int custom_string;
};
Custom Parameter Value
union ppd_cpvalue_u {
float custom_curve;
int custom_int;
float custom_invcurve;
char *custom_passcode;
char *custom_password;
float custom_points;
float custom_real;
char *custom_string;
};
Conformance Levels
Colorspaces
Order dependency sections
Status Codes
UI Types