Introduction

The CUPS PPD API provides...

General Usage

The <cups/ppd.h> header file must be included to use the ppd functions.

Programs using these functions must be linked to the CUPS library: libcups.a, libcups.so.2, libcups.2.dylib, libcups_s.a, or libcups2.lib depending on the platform. The following command compiles myprogram.c using GCC and the CUPS library:

gcc -o myprogram myprogram.c -lcups

Compatibility

Unless otherwise specified, the PPD API functions require CUPS 1.1 or higher.

Contents

Enumerations

ppd_cs_e

Description

Colorspaces

Values

NameDescription
PPD_CS_CMY CMY colorspace
PPD_CS_CMYK CMYK colorspace
PPD_CS_GRAY Grayscale colorspace
PPD_CS_N DeviceN colorspace
PPD_CS_RGB RGB colorspace
PPD_CS_RGBK RGBK (K = gray) colorspace

 CUPS 1.2 ppd_ext_ui_e

Description

Extended UI Types

Values

NameDescription
PPD_UI_CUPS_CURVE Specify start, end, and gamma numbers
PPD_UI_CUPS_GAMMA Specify a gamma number
PPD_UI_CUPS_INTEGER Specify an integer number
PPD_UI_CUPS_INTEGER_ARRAY Specify an array of integer numbers
PPD_UI_CUPS_REAL Specify a real number
PPD_UI_CUPS_REAL_ARRAY Specify an array of real numbers
PPD_UI_CUPS_TEXT Specify a string
PPD_UI_CUPS_XY_ARRAY Specify an array of X/Y real numbers

ppd_section_e

Description

Order dependency sections

Values

NameDescription
PPD_ORDER_ANY Option code can be anywhere in the file
PPD_ORDER_DOCUMENT ... must be in the DocumentSetup section
PPD_ORDER_EXIT ... must be sent prior to the document
PPD_ORDER_JCL ... must be sent as a JCL command
PPD_ORDER_PAGE ... must be in the PageSetup section
PPD_ORDER_PROLOG ... must be in the Prolog section

ppd_status_e

Description

Types and structures...

Values

NameDescription
PPD_ALLOC_ERROR Memory allocation error
PPD_BAD_OPEN_GROUP Bad OpenGroup
PPD_BAD_OPEN_UI Bad OpenUI/JCLOpenUI
PPD_BAD_ORDER_DEPENDENCY Bad OrderDependency
PPD_BAD_UI_CONSTRAINTS Bad UIConstraints
PPD_FILE_OPEN_ERROR Unable to open PPD file
PPD_ILLEGAL_CHARACTER Illegal control character
PPD_ILLEGAL_MAIN_KEYWORD Illegal main keyword string
PPD_ILLEGAL_OPTION_KEYWORD Illegal option keyword string
PPD_ILLEGAL_TRANSLATION Illegal translation string
PPD_ILLEGAL_WHITESPACE Illegal whitespace character
PPD_INTERNAL_ERROR Internal error
PPD_LINE_TOO_LONG Line longer than 255 chars
PPD_MISSING_ASTERISK Missing asterisk in column 0
PPD_MISSING_PPDADOBE4 Missing PPD-Adobe-4.x header
PPD_MISSING_VALUE Missing value string
PPD_NESTED_OPEN_GROUP OpenGroup without a CloseGroup first
PPD_NESTED_OPEN_UI OpenUI/JCLOpenUI without a CloseUI/JCLCloseUI first
PPD_NULL_FILE NULL PPD file pointer
PPD_OK OK

ppd_ui_e

Description

UI Types

Values

NameDescription
PPD_UI_BOOLEAN True or False option
PPD_UI_PICKMANY Pick zero or more from a list
PPD_UI_PICKONE Pick one from a list

Functions

ppdClose()

Description

Free all memory used by the PPD file.

Syntax

void
ppdClose(
    ppd_file_t * ppd);

Arguments

NameDescription
ppdPPD file record

Returns

Nothing.

ppdCollect()

Description

Collect all marked options that reside in the specified section.

Syntax

int
ppdCollect(
    ppd_file_t * ppd,
    ppd_section_t section,
    ppd_choice_t *** choices);

Arguments

NameDescription
ppdPPD file data
sectionSection to collect
choicesPointers to choices

Returns

Number of options marked

ppdConflicts()

Description

Check to see if there are any conflicts.

Syntax

int
ppdConflicts(
    ppd_file_t * ppd);

Arguments

NameDescription
ppdPPD to check

Returns

Number of conflicts found

ppdEmit()

Description

Emit code for marked options to a file.

Syntax

int
ppdEmit(
    ppd_file_t * ppd,
    FILE * fp,
    ppd_section_t section);

Arguments

NameDescription
ppdPPD file record
fpFile to write to
sectionSection to write

Returns

0 on success, -1 on failure

ppdEmitFd()

Description

Emit code for marked options to a file.

Syntax

int
ppdEmitFd(
    ppd_file_t * ppd,
    int fd,
    ppd_section_t section);

Arguments

NameDescription
ppdPPD file record
fdFile to write to
sectionSection to write

Returns

0 on success, -1 on failure

ppdEmitJCL()

Description

Emit code for JCL options to a file.

Syntax

int
ppdEmitJCL(
    ppd_file_t * ppd,
    FILE * fp,
    int job_id,
    const char * user,
    const char * title);

Arguments

NameDescription
ppdPPD file record
fpFile to write to
job_idJob ID
userUsername
titleTitle

Returns

0 on success, -1 on failure

 CUPS 1.2 ppdEmitJCLEnd()

Description

Emit JCLEnd code to a file.

Syntax

int
ppdEmitJCLEnd(
    ppd_file_t * ppd,
    FILE * fp);

Arguments

NameDescription
ppdPPD file record
fpFile to write to

Returns

0 on success, -1 on failure

 CUPS 1.1.19 ppdErrorString()

Description

Returns the text assocated with a status.

Syntax

const char *
ppdErrorString(
    ppd_status_t status);

Arguments

NameDescription
statusPPD status

Returns

Status string

 CUPS 1.1.19 ppdFindAttr()

Description

Find the first matching attribute...

Syntax

ppd_attr_t *
ppdFindAttr(
    ppd_file_t * ppd,
    const char * name,
    const char * spec);

Arguments

NameDescription
ppdPPD file data
nameAttribute name
specSpecifier string or NULL

Returns

Attribute or NULL if not found

ppdFindChoice()

Description

Return a pointer to an option choice.

Syntax

ppd_choice_t *
ppdFindChoice(
    ppd_option_t * o,
    const char * choice);

Arguments

NameDescription
oPointer to option
choiceName of choice

Returns

Choice pointer or NULL

ppdFindMarkedChoice()

Description

Return the marked choice for the specified option.

Syntax

ppd_choice_t *
ppdFindMarkedChoice(
    ppd_file_t * ppd,
    const char * option);

Arguments

NameDescription
ppdPPD file
optionKeyword/option name

Returns

Pointer to choice or NULL

 CUPS 1.1.19 ppdFindNextAttr()

Description

Find the next matching attribute...

Syntax

ppd_attr_t *
ppdFindNextAttr(
    ppd_file_t * ppd,
    const char * name,
    const char * spec);

Arguments

NameDescription
ppdPPD file data
nameAttribute name
specSpecifier string or NULL

Returns

Attribute or NULL if not found

ppdFindOption()

Description

Return a pointer to the specified option.

Syntax

ppd_option_t *
ppdFindOption(
    ppd_file_t * ppd,
    const char * option);

Arguments

NameDescription
ppdPPD file data
optionOption/Keyword name

Returns

Pointer to option or NULL

ppdIsMarked()

Description

Check to see if an option is marked...

Syntax

int
ppdIsMarked(
    ppd_file_t * ppd,
    const char * option,
    const char * choice);

Arguments

NameDescription
ppdPPD file data
optionOption/Keyword name
choiceChoice name

Returns

Non-zero if option is marked

 CUPS 1.1.19 ppdLastError()

Description

Return the status from the last ppdOpen*().

Syntax

ppd_status_t
ppdLastError(
    int * line);

Arguments

NameDescription
lineLine number

Returns

Status code

ppdMarkDefaults()

Description

Mark all default options in the PPD file.

Syntax

void
ppdMarkDefaults(
    ppd_file_t * ppd);

Arguments

NameDescription
ppdPPD file record

Returns

Nothing.

ppdMarkOption()

Description

Mark an option in a PPD file. Notes: -1 is returned if the given option would conflict with any currently selected option.

Syntax

int
ppdMarkOption(
    ppd_file_t * ppd,
    const char * option,
    const char * choice);

Arguments

NameDescription
ppdPPD file record
optionKeyword
choiceOption name

Returns

Number of conflicts

ppdOpen()

Description

Read a PPD file into memory.

Syntax

ppd_file_t *
ppdOpen(
    FILE * fp);

Arguments

NameDescription
fpFile to read from

Returns

PPD file record

 CUPS 1.2 ppdOpen2()

Description

Read a PPD file into memory.

Syntax

ppd_file_t *
ppdOpen2(
    cups_file_t * fp);

Arguments

NameDescription
fpFile to read from

Returns

PPD file record

ppdOpenFd()

Description

Read a PPD file into memory.

Syntax

ppd_file_t *
ppdOpenFd(
    int fd);

Arguments

NameDescription
fdFile to read from

Returns

PPD file record

ppdOpenFile()

Description

Read a PPD file into memory.

Syntax

ppd_file_t *
ppdOpenFile(
    const char * filename);

Arguments

NameDescription
filenameFile to read from

Returns

PPD file record

ppdPageLength()

Description

Get the page length for the given size.

Syntax

float
ppdPageLength(
    ppd_file_t * ppd,
    const char * name);

Arguments

NameDescription
ppdPPD file
nameSize name

Returns

Length of page in points or 0.0

ppdPageSize()

Description

Get the page size record for the given size.

Syntax

ppd_size_t *
ppdPageSize(
    ppd_file_t * ppd,
    const char * name);

Arguments

NameDescription
ppdPPD file record
nameSize name

Returns

Size record for page or NULL

ppdPageWidth()

Description

Get the page width for the given size.

Syntax

float
ppdPageWidth(
    ppd_file_t * ppd,
    const char * name);

Arguments

NameDescription
ppdPPD file record
nameSize name

Returns

Width of page in points or 0.0

 CUPS 1.1.20 ppdSetConformance()

Description

Set the conformance level for PPD files.

Syntax

void
ppdSetConformance(
    ppd_conform_t c);

Arguments

NameDescription
cConformance level

Returns

Nothing.

Structures

 CUPS 1.1.19 ppd_attr_str

Description

PPD Attribute Structure

Definition

struct ppd_attr_str
{
  char name[PPD_MAX_NAME];
  char spec[PPD_MAX_NAME];
  char text[PPD_MAX_TEXT];
  char * value;
};

Members

NameDescription
name[PPD_MAX_NAME] Name of attribute (cupsXYZ)
spec[PPD_MAX_NAME] Specifier string, if any
text[PPD_MAX_TEXT] Human-readable text, if any
value Value string

ppd_choice_str

Description

Option choices

Definition

struct ppd_choice_str
{
  char choice[PPD_MAX_NAME];
  char * code;
  char marked;
  ppd_option_t * option;
  char text[PPD_MAX_TEXT];
};

Members

NameDescription
choice[PPD_MAX_NAME] Computer-readable option name
code Code to send for this option
marked 0 if not selected, 1 otherwise
option Pointer to parent option structure
text[PPD_MAX_TEXT] Human-readable option name

ppd_emul_str

Description

Emulators

Definition

struct ppd_emul_str
{
  char name[PPD_MAX_NAME];
  char * start;
  char * stop;
};

Members

NameDescription
name[PPD_MAX_NAME] Emulator name
start Code to switch to this emulation
stop Code to stop this emulation

 CUPS 1.2 ppd_ext_option_str

Description

Extended Options

Definition

struct ppd_ext_option_str
{
  char * code;
  char keyword[PPD_MAX_NAME];
  int marked;
  int num_params;
  ppd_option_t * option;
  ppd_ext_param_t ** params;
};

Members

NameDescription
code Generic PS code for extended options
keyword[PPD_MAX_NAME] Name of option that is being extended...
marked Extended option is marked
num_params Number of parameters
option Option that is being extended...
params Parameters

 CUPS 1.2 ppd_ext_param_str

Description

Extended Parameter

Definition

struct ppd_ext_param_str
{
  ppd_ext_value_t * defval;
  char keyword[PPD_MAX_NAME];
  ppd_ext_value_t * maxval;
  ppd_ext_value_t * minval;
  char text[PPD_MAX_TEXT];
  ppd_ext_value_t * value;
};

Members

NameDescription
defval Default values
keyword[PPD_MAX_NAME] Parameter name
maxval Maximum numeric values
minval Minimum numeric values
text[PPD_MAX_TEXT] Human-readable text
value Current values

ppd_file_str

Description

Files

Definition

struct ppd_file_str
{
  int accurate_screens;
  ppd_attr_t ** attrs;
  int color_device;
  ppd_cs_t colorspace;
  ppd_const_t * consts;
  int contone_only;
  int cur_attr;
  float custom_margins[4];
  float custom_max[2];
  float custom_min[2];
  ppd_emul_t * emulations;
  ppd_ext_option_t ** extended;
  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_attrs;
  int num_consts;
  int num_emulations;
  int num_extended;
  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;
};

Members

NameDescription
accurate_screens 1 = supports accurate screens, 0 = not
attrs  CUPS 1.1.19 Attributes
color_device 1 = color device, 0 = grayscale
colorspace Default colorspace
consts UI/Non-UI constraints
contone_only 1 = continuous tone only, 0 = not
cur_attr  CUPS 1.1.19 Current attribute
custom_margins[4] Margins around page
custom_max[2] Maximum variable page size
custom_min[2] Minimum variable page size
emulations Emulations and the code to invoke them
extended  CUPS 1.2 Extended options
filters Filter strings...
flip_duplex  CUPS 1.1 1 = Flip page for back sides
fonts Pre-loaded fonts
groups UI groups
jcl_begin Start JCL commands
jcl_end End JCL commands
jcl_ps Enter PostScript interpreter
landscape -90 or 90
lang_encoding Language encoding
lang_version Language version (English, Spanish, etc.)
language_level Language level of device
manual_copies 1 = Copies done manually, 0 = hardware
manufacturer Manufacturer name
model_number Device-specific model number
modelname Model name (general)
nickname Nickname (specific)
num_attrs  CUPS 1.1.19 Number of attributes
num_consts Number of UI/Non-UI constraints
num_emulations Number of emulations supported
num_extended  CUPS 1.2 Number of extended options
num_filters Number of filters
num_fonts Number of pre-loaded fonts
num_groups Number of UI groups
num_profiles Number of sRGB color profiles
num_sizes Number of page sizes
patches Patch commands to be sent to printer
pcfilename  CUPS 1.1.19 PCFileName string
product Product name (from PS RIP/interpreter)
profiles sRGB color profiles
protocols  CUPS 1.1.19 Protocols (BCP, TBCP) string
shortnickname Short version of nickname
sizes Page sizes
throughput Pages per minute
ttrasterizer Truetype rasterizer
variable_sizes 1 = supports variable sizes, 0 = doesn't

ppd_group_str

Description

Groups

Definition

struct ppd_group_str
{
  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_str * subgroups;
};

Members

NameDescription
PPD_MAX_NAME] Human-readable group name
name[PPD_MAX_NAME]  CUPS 1.1.18 Group name
num_options Number of options
num_subgroups Number of sub-groups
options Options
subgroups Sub-groups (max depth = 1)

ppd_option_str

Description

Options

Definition

struct ppd_option_str
{
  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;
};

Members

NameDescription
choices Option choices
conflicted 0 if no conflicts exist, 1 otherwise
defchoice[PPD_MAX_NAME] Default option choice
keyword[PPD_MAX_NAME] Option keyword name ("PageSize", etc.)
num_choices Number of option choices
order Order number
section Section for command
text[PPD_MAX_TEXT] Human-readable text
ui Type of UI option

ppd_profile_str

Description

sRGB Color Profiles

Definition

struct ppd_profile_str
{
  float density;
  float gamma;
  float matrix[3][3];
  char media_type[PPD_MAX_NAME];
  char resolution[PPD_MAX_NAME];
};

Members

NameDescription
density Ink density to use
gamma Gamma correction to use
matrix[3][3] Transform matrix
media_type[PPD_MAX_NAME] Media type or "-"
resolution[PPD_MAX_NAME] Resolution or "-"

ppd_size_str

Description

Page Sizes

Definition

struct ppd_size_str
{
  float bottom;
  float left;
  float length;
  int marked;
  char name[PPD_MAX_NAME];
  float right;
  float top;
  float width;
};

Members

NameDescription
bottom Bottom printable margin in points
left Left printable margin in points
length Length of media in points
marked Page size selected?
name[PPD_MAX_NAME] Media size option
right Right printable margin in points
top Top printable margin in points
width Width of media in points

Types

 CUPS 1.1.19 ppd_attr_t

Description

PPD Attribute Structure

Definition

typedef struct ppd_attr_str ppd_attr_t;

ppd_choice_t

Description

Option choices

Definition

typedef struct ppd_choice_str ppd_choice_t;

ppd_const_t

Description

Constraints

Definition

typedef struct ppd_const_t;

ppd_emul_t

Description

Emulators

Definition

typedef struct ppd_emul_str ppd_emul_t;

 CUPS 1.2 ppd_ext_option_t

Description

Extended Options

Definition

typedef struct ppd_ext_option_str ppd_ext_option_t;

 CUPS 1.2 ppd_ext_param_t

Description

Extended Parameter

Definition

typedef struct ppd_ext_param_str ppd_ext_param_t;

 CUPS 1.2 ppd_ext_ui_t

Description

Extended UI Types

Definition

typedef enum ppd_ext_ui_e ppd_ext_ui_t;

 CUPS 1.2 ppd_ext_value_t

Description

Extended Values

Definition

typedef union ppd_ext_value_u ppd_ext_value_t;

ppd_file_t

Description

Files

Definition

typedef struct ppd_file_str ppd_file_t;

ppd_group_t

Description

Groups

Definition

typedef struct ppd_group_str ppd_group_t;

ppd_option_t

Description

Options

Definition

typedef struct ppd_option_str ppd_option_t;

ppd_profile_t

Description

sRGB Color Profiles

Definition

typedef struct ppd_profile_str ppd_profile_t;

ppd_section_t

Description

Order dependency sections

Definition

typedef enum ppd_section_e ppd_section_t;

ppd_size_t

Description

Page Sizes

Definition

typedef struct ppd_size_str ppd_size_t;

ppd_ui_t

Description

UI Types

Definition

typedef enum ppd_ui_e ppd_ui_t;

Unions

 CUPS 1.2 ppd_ext_value_u

Description

Extended Values

Definition

union ppd_ext_value_u
{
  float gamma;
  int integer;
  float real;
  char * text;
};

Members

NameDescription
gamma Gamma value
integer Integer value
real Real value
text Text value