1*5e7646d2SAndroid Build Coastguard Worker<!-- 2*5e7646d2SAndroid Build Coastguard Worker PPD API introduction for CUPS. 3*5e7646d2SAndroid Build Coastguard Worker 4*5e7646d2SAndroid Build Coastguard Worker Copyright © 2007-2019 by Apple Inc. 5*5e7646d2SAndroid Build Coastguard Worker Copyright © 1997-2006 by Easy Software Products, all rights reserved. 6*5e7646d2SAndroid Build Coastguard Worker 7*5e7646d2SAndroid Build Coastguard Worker Licensed under Apache License v2.0. See the file "LICENSE" for more 8*5e7646d2SAndroid Build Coastguard Worker information. 9*5e7646d2SAndroid Build Coastguard Worker--> 10*5e7646d2SAndroid Build Coastguard Worker 11*5e7646d2SAndroid Build Coastguard Worker<h2 class='title'><a name='OVERVIEW'>Overview</a></h2> 12*5e7646d2SAndroid Build Coastguard Worker 13*5e7646d2SAndroid Build Coastguard Worker<blockquote><b>Note:</b> 14*5e7646d2SAndroid Build Coastguard Worker 15*5e7646d2SAndroid Build Coastguard Worker<p>The PPD API was deprecated in CUPS 1.6/macOS 10.8. Please use the new Job Ticket APIs in the <a href="cupspm.html">CUPS Programming Manual</a> documentation. These functions will be removed in a future release of CUPS.</p> 16*5e7646d2SAndroid Build Coastguard Worker</blockquote> 17*5e7646d2SAndroid Build Coastguard Worker 18*5e7646d2SAndroid Build Coastguard Worker<p>The CUPS PPD API provides read-only access the data in PostScript Printer 19*5e7646d2SAndroid Build Coastguard WorkerDescription ("PPD") files which are used for all printers with a driver. With 20*5e7646d2SAndroid Build Coastguard Workerit you can obtain the data necessary to display printer options to users, mark 21*5e7646d2SAndroid Build Coastguard Workeroption choices and check for conflicting choices, and output marked choices in 22*5e7646d2SAndroid Build Coastguard WorkerPostScript output. The <a href="#ppd_file_t"><code>ppd_file_t</code></a> 23*5e7646d2SAndroid Build Coastguard Workerstructure contains all of the information in a PPD file.</p> 24*5e7646d2SAndroid Build Coastguard Worker 25*5e7646d2SAndroid Build Coastguard Worker<blockquote><b>Note:</b> 26*5e7646d2SAndroid Build Coastguard Worker 27*5e7646d2SAndroid Build Coastguard Worker<p>The CUPS PPD API uses the terms "option" and "choice" instead of the Adobe 28*5e7646d2SAndroid Build Coastguard Workerterms "MainKeyword" and "OptionKeyword" to refer to specific printer options and 29*5e7646d2SAndroid Build Coastguard Workerfeatures. CUPS also treats option ("MainKeyword") and choice ("OptionKeyword") 30*5e7646d2SAndroid Build Coastguard Workervalues as case-insensitive strings, so option "InputSlot" and choice "Upper" 31*5e7646d2SAndroid Build Coastguard Workerare equivalent to "inputslot" and "upper", respectively.</p> 32*5e7646d2SAndroid Build Coastguard Worker</blockquote> 33*5e7646d2SAndroid Build Coastguard Worker 34*5e7646d2SAndroid Build Coastguard Worker 35*5e7646d2SAndroid Build Coastguard Worker<h3><a name="LOADING">Loading a PPD File</a></h3> 36*5e7646d2SAndroid Build Coastguard Worker 37*5e7646d2SAndroid Build Coastguard Worker<p>The <a href="#ppdOpenFile"><code>ppdOpenFile</code></a> function "opens" a 38*5e7646d2SAndroid Build Coastguard WorkerPPD file and loads it into memory. For example, the following code opens the 39*5e7646d2SAndroid Build Coastguard Workercurrent printer's PPD file in a CUPS filter:</p> 40*5e7646d2SAndroid Build Coastguard Worker 41*5e7646d2SAndroid Build Coastguard Worker<pre class="example"> 42*5e7646d2SAndroid Build Coastguard Worker#include <cups/ppd.h> 43*5e7646d2SAndroid Build Coastguard Worker 44*5e7646d2SAndroid Build Coastguard Worker<a href="#ppd_file_t">ppd_file_t</a> *ppd = <a href="#ppdOpenFile">ppdOpenFile</a>(getenv("PPD")); 45*5e7646d2SAndroid Build Coastguard Worker</pre> 46*5e7646d2SAndroid Build Coastguard Worker 47*5e7646d2SAndroid Build Coastguard Worker<p>The return value is a pointer to a new 48*5e7646d2SAndroid Build Coastguard Worker<a href="#ppd_file_t"><code>ppd_file_t</code></a> structure or <code>NULL</code> 49*5e7646d2SAndroid Build Coastguard Workerif the PPD file does not exist or cannot be loaded. The 50*5e7646d2SAndroid Build Coastguard Worker<a href="#ppdClose"><code>ppdClose</code></a> function frees the memory used 51*5e7646d2SAndroid Build Coastguard Workerby the structure:</p> 52*5e7646d2SAndroid Build Coastguard Worker 53*5e7646d2SAndroid Build Coastguard Worker<pre class="example"> 54*5e7646d2SAndroid Build Coastguard Worker#include <cups/ppd.h> 55*5e7646d2SAndroid Build Coastguard Worker 56*5e7646d2SAndroid Build Coastguard Worker<a href="#ppd_file_t">ppd_file_t</a> *ppd; 57*5e7646d2SAndroid Build Coastguard Worker 58*5e7646d2SAndroid Build Coastguard Worker<a href="#ppdClose">ppdClose</a>(ppd); 59*5e7646d2SAndroid Build Coastguard Worker</pre> 60*5e7646d2SAndroid Build Coastguard Worker 61*5e7646d2SAndroid Build Coastguard Worker<p>Once closed, pointers to the <a href="#ppd_file_t"><code>ppd_file_t</code></a> 62*5e7646d2SAndroid Build Coastguard Workerstructure and any data in it will no longer be valid.</p> 63*5e7646d2SAndroid Build Coastguard Worker 64*5e7646d2SAndroid Build Coastguard Worker<h3><a name="OPTIONS_AND_GROUPS">Options and Groups</a></h3> 65*5e7646d2SAndroid Build Coastguard Worker 66*5e7646d2SAndroid Build Coastguard Worker<p>PPD files support multiple options, which are stored in arrays of 67*5e7646d2SAndroid Build Coastguard Worker<a href="#ppd_option_t"><code>ppd_option_t</code></a> and 68*5e7646d2SAndroid Build Coastguard Worker<a href="#ppd_choice_t"><code>ppd_choice_t</code></a> structures.</p> 69*5e7646d2SAndroid Build Coastguard Worker 70*5e7646d2SAndroid Build Coastguard Worker<p>Each option in turn is associated with a group stored in a 71*5e7646d2SAndroid Build Coastguard Worker<a href="#ppd_group_t"><code>ppd_group_t</code></a> structure. Groups can be 72*5e7646d2SAndroid Build Coastguard Workerspecified in the PPD file; if an option is not associated with a group 73*5e7646d2SAndroid Build Coastguard Workerthen it is put in an automatically-generated "General" group. Groups can also 74*5e7646d2SAndroid Build Coastguard Workerhave sub-groups, however CUPS currently ignores sub-groups because of past 75*5e7646d2SAndroid Build Coastguard Workerabuses of this functionality.</p> 76*5e7646d2SAndroid Build Coastguard Worker 77*5e7646d2SAndroid Build Coastguard Worker<p>Option choices are selected by marking them using one of three functions. The 78*5e7646d2SAndroid Build Coastguard Workerfirst is <a href="#ppdMarkDefaults"><code>ppdMarkDefaults</code></a> which 79*5e7646d2SAndroid Build Coastguard Workerselects all of the default options in the PPD file:</p> 80*5e7646d2SAndroid Build Coastguard Worker 81*5e7646d2SAndroid Build Coastguard Worker<pre class="example"> 82*5e7646d2SAndroid Build Coastguard Worker#include <cups/ppd.h> 83*5e7646d2SAndroid Build Coastguard Worker 84*5e7646d2SAndroid Build Coastguard Worker<a href="#ppd_file_t">ppd_file_t</a> *ppd; 85*5e7646d2SAndroid Build Coastguard Worker 86*5e7646d2SAndroid Build Coastguard Worker<a href="#ppdMarkDefaults">ppdMarkDefaults</a>(ppd); 87*5e7646d2SAndroid Build Coastguard Worker</pre> 88*5e7646d2SAndroid Build Coastguard Worker 89*5e7646d2SAndroid Build Coastguard Worker<p>The second is <a href="#ppdMarkOption"><code>ppdMarkOption</code></a> 90*5e7646d2SAndroid Build Coastguard Workerwhich selects a single option choice in the PPD file. For example, the following 91*5e7646d2SAndroid Build Coastguard Workercode selects the upper paper tray:</p> 92*5e7646d2SAndroid Build Coastguard Worker 93*5e7646d2SAndroid Build Coastguard Worker<pre class="example"> 94*5e7646d2SAndroid Build Coastguard Worker#include <cups/ppd.h> 95*5e7646d2SAndroid Build Coastguard Worker 96*5e7646d2SAndroid Build Coastguard Worker<a href="#ppd_file_t">ppd_file_t</a> *ppd; 97*5e7646d2SAndroid Build Coastguard Worker 98*5e7646d2SAndroid Build Coastguard Worker<a href="#ppdMarkOption">ppdMarkOption</a>(ppd, "InputSlot", "Upper"); 99*5e7646d2SAndroid Build Coastguard Worker</pre> 100*5e7646d2SAndroid Build Coastguard Worker 101*5e7646d2SAndroid Build Coastguard Worker<p>The last function is 102*5e7646d2SAndroid Build Coastguard Worker<a href="#cupsMarkOptions"><code>cupsMarkOptions</code></a> which selects 103*5e7646d2SAndroid Build Coastguard Workermultiple option choices in the PPD file from an array of CUPS options, mapping 104*5e7646d2SAndroid Build Coastguard WorkerIPP attributes like "media" and "sides" to their corresponding PPD options. You 105*5e7646d2SAndroid Build Coastguard Workertypically use this function in a print filter with 106*5e7646d2SAndroid Build Coastguard Worker<code>cupsParseOptions</code> and 107*5e7646d2SAndroid Build Coastguard Worker<a href="#ppdMarkDefaults"><code>ppdMarkDefaults</code></a> to select all of 108*5e7646d2SAndroid Build Coastguard Workerthe option choices needed for the job, for example:</p> 109*5e7646d2SAndroid Build Coastguard Worker 110*5e7646d2SAndroid Build Coastguard Worker<pre class="example"> 111*5e7646d2SAndroid Build Coastguard Worker#include <cups/ppd.h> 112*5e7646d2SAndroid Build Coastguard Worker 113*5e7646d2SAndroid Build Coastguard Worker<a href="#ppd_file_t">ppd_file_t</a> *ppd = <a href="#ppdOpenFile">ppdOpenFile</a>(getenv("PPD")); 114*5e7646d2SAndroid Build Coastguard Workercups_option_t *options = NULL; 115*5e7646d2SAndroid Build Coastguard Workerint num_options = cupsParseOptions(argv[5], 0, &options); 116*5e7646d2SAndroid Build Coastguard Worker 117*5e7646d2SAndroid Build Coastguard Worker<a href="#ppdMarkDefaults">ppdMarkDefaults</a>(ppd); 118*5e7646d2SAndroid Build Coastguard Worker<a href="#cupsMarkOptions">cupsMarkOptions</a>(ppd, num_options, options); 119*5e7646d2SAndroid Build Coastguard WorkercupsFreeOptions(num_options, options); 120*5e7646d2SAndroid Build Coastguard Worker</pre> 121*5e7646d2SAndroid Build Coastguard Worker 122*5e7646d2SAndroid Build Coastguard Worker 123*5e7646d2SAndroid Build Coastguard Worker<h3><a name="CONSTRAINTS">Constraints</a></h3> 124*5e7646d2SAndroid Build Coastguard Worker 125*5e7646d2SAndroid Build Coastguard Worker<p>PPD files support specification of conflict conditions, called 126*5e7646d2SAndroid Build Coastguard Workerconstraints, between different options. Constraints are stored in an array of 127*5e7646d2SAndroid Build Coastguard Worker<a href="#ppd_const_t"><code>ppd_const_t</code></a> structures which specify 128*5e7646d2SAndroid Build Coastguard Workerthe options and choices that conflict with each other. The 129*5e7646d2SAndroid Build Coastguard Worker<a href="#ppdConflicts"><code>ppdConflicts</code></a> function tells you 130*5e7646d2SAndroid Build Coastguard Workerhow many of the selected options are incompatible. Since constraints are 131*5e7646d2SAndroid Build Coastguard Workernormally specified in pairs, the returned value is typically an even number.</p> 132*5e7646d2SAndroid Build Coastguard Worker 133*5e7646d2SAndroid Build Coastguard Worker 134*5e7646d2SAndroid Build Coastguard Worker<h3><a name="PAGE_SIZES">Page Sizes</a></h3> 135*5e7646d2SAndroid Build Coastguard Worker 136*5e7646d2SAndroid Build Coastguard Worker<p>Page sizes are special options which have physical dimensions and margins 137*5e7646d2SAndroid Build Coastguard Workerassociated with them. The size information is stored in 138*5e7646d2SAndroid Build Coastguard Worker<a href="#ppd_size_t"><code>ppd_size_t</code></a> structures and is available 139*5e7646d2SAndroid Build Coastguard Workerby looking up the named size with the 140*5e7646d2SAndroid Build Coastguard Worker<a href="#ppdPageSize"><code>ppdPageSize</code></a> function. The page size and 141*5e7646d2SAndroid Build Coastguard Workermargins are returned in units called points; there are 72 points per inch. If 142*5e7646d2SAndroid Build Coastguard Workeryou pass <code>NULL</code> for the size, the currently selected size is 143*5e7646d2SAndroid Build Coastguard Workerreturned:</p> 144*5e7646d2SAndroid Build Coastguard Worker 145*5e7646d2SAndroid Build Coastguard Worker<pre class="example"> 146*5e7646d2SAndroid Build Coastguard Worker#include <cups/ppd.h> 147*5e7646d2SAndroid Build Coastguard Worker 148*5e7646d2SAndroid Build Coastguard Worker<a href="#ppd_file_t">ppd_file_t</a> *ppd; 149*5e7646d2SAndroid Build Coastguard Worker<a href="#ppd_size_t">ppd_size_t</a> *size = <a href="#ppdPageSize">ppdPageSize</a>(ppd, NULL); 150*5e7646d2SAndroid Build Coastguard Worker</pre> 151*5e7646d2SAndroid Build Coastguard Worker 152*5e7646d2SAndroid Build Coastguard Worker<p>Besides the standard page sizes listed in a PPD file, some printers 153*5e7646d2SAndroid Build Coastguard Workersupport variable or custom page sizes. Custom page sizes are supported if the 154*5e7646d2SAndroid Build Coastguard Worker<code>variables_sizes</code> member of the 155*5e7646d2SAndroid Build Coastguard Worker<a href="#ppd_file_t"><code>ppd_file_t</code></a> structure is non-zero. 156*5e7646d2SAndroid Build Coastguard WorkerThe <code>custom_min</code>, <code>custom_max</code>, and 157*5e7646d2SAndroid Build Coastguard Worker<code>custom_margins</code> members of the 158*5e7646d2SAndroid Build Coastguard Worker<a href="#ppd_file_t"><code>ppd_file_t</code></a> structure define the limits 159*5e7646d2SAndroid Build Coastguard Workerof the printable area. To get the resulting media size, use a page size string 160*5e7646d2SAndroid Build Coastguard Workerof the form "Custom.<I>width</I>x<I>length</I>", where "width" and "length" are 161*5e7646d2SAndroid Build Coastguard Workerin points. Custom page size names can also be specified in inches 162*5e7646d2SAndroid Build Coastguard Worker("Custom.<i>width</i>x<i>height</i>in"), centimeters 163*5e7646d2SAndroid Build Coastguard Worker("Custom.<i>width</i>x<i>height</i>cm"), or millimeters 164*5e7646d2SAndroid Build Coastguard Worker("Custom.<i>width</i>x<i>height</i>mm"):</p> 165*5e7646d2SAndroid Build Coastguard Worker 166*5e7646d2SAndroid Build Coastguard Worker<pre class="example"> 167*5e7646d2SAndroid Build Coastguard Worker#include <cups/ppd.h> 168*5e7646d2SAndroid Build Coastguard Worker 169*5e7646d2SAndroid Build Coastguard Worker<a href="#ppd_file_t">ppd_file_t</a> *ppd; 170*5e7646d2SAndroid Build Coastguard Worker 171*5e7646d2SAndroid Build Coastguard Worker/* Get an 576x720 point custom page size */ 172*5e7646d2SAndroid Build Coastguard Worker<a href="#ppd_size_t">ppd_size_t</a> *size = <a href="#ppdPageSize">ppdPageSize</a>(ppd, "Custom.576x720"); 173*5e7646d2SAndroid Build Coastguard Worker 174*5e7646d2SAndroid Build Coastguard Worker/* Get an 8x10 inch custom page size */ 175*5e7646d2SAndroid Build Coastguard Worker<a href="#ppd_size_t">ppd_size_t</a> *size = <a href="#ppdPageSize">ppdPageSize</a>(ppd, "Custom.8x10in"); 176*5e7646d2SAndroid Build Coastguard Worker 177*5e7646d2SAndroid Build Coastguard Worker/* Get a 100x200 millimeter custom page size */ 178*5e7646d2SAndroid Build Coastguard Worker<a href="#ppd_size_t">ppd_size_t</a> *size = <a href="#ppdPageSize">ppdPageSize</a>(ppd, "Custom.100x200mm"); 179*5e7646d2SAndroid Build Coastguard Worker 180*5e7646d2SAndroid Build Coastguard Worker/* Get a 12.7x34.5 centimeter custom page size */ 181*5e7646d2SAndroid Build Coastguard Worker<a href="#ppd_size_t">ppd_size_t</a> *size = <a href="#ppdPageSize">ppdPageSize</a>(ppd, "Custom.12.7x34.5cm"); 182*5e7646d2SAndroid Build Coastguard Worker</pre> 183*5e7646d2SAndroid Build Coastguard Worker 184*5e7646d2SAndroid Build Coastguard Worker<p>If the PPD does not support variable page sizes, the 185*5e7646d2SAndroid Build Coastguard Worker<a href="#ppdPageSize"><code>ppdPageSize</code></a> function will return 186*5e7646d2SAndroid Build Coastguard Worker<code>NULL</code>.</p> 187*5e7646d2SAndroid Build Coastguard Worker 188*5e7646d2SAndroid Build Coastguard Worker 189*5e7646d2SAndroid Build Coastguard Worker<h3><a name="ATTRIBUTES">Attributes</a></h3> 190*5e7646d2SAndroid Build Coastguard Worker 191*5e7646d2SAndroid Build Coastguard Worker<p>Every PPD file is composed of one or more attributes. Most of these 192*5e7646d2SAndroid Build Coastguard Workerattributes are used to define groups, options, choices, and page sizes, 193*5e7646d2SAndroid Build Coastguard Workerhowever several informational attributes may be present which you can access 194*5e7646d2SAndroid Build Coastguard Workerin your program or filter. Attributes normally look like one of the following 195*5e7646d2SAndroid Build Coastguard Workerexamples in a PPD file:</p> 196*5e7646d2SAndroid Build Coastguard Worker 197*5e7646d2SAndroid Build Coastguard Worker<pre class="example"> 198*5e7646d2SAndroid Build Coastguard Worker*name: "value" 199*5e7646d2SAndroid Build Coastguard Worker*name spec: "value" 200*5e7646d2SAndroid Build Coastguard Worker*name spec/text: "value" 201*5e7646d2SAndroid Build Coastguard Worker</pre> 202*5e7646d2SAndroid Build Coastguard Worker 203*5e7646d2SAndroid Build Coastguard Worker<p>The <a href="#ppdFindAttr"><code>ppdFindAttr</code></a> and 204*5e7646d2SAndroid Build Coastguard Worker<a href="#ppdFindNextAttr"><code>ppdFindNextAttr</code></a> functions find the 205*5e7646d2SAndroid Build Coastguard Workerfirst and next instances, respectively, of the named attribute with the given 206*5e7646d2SAndroid Build Coastguard Worker"spec" string and return a <a href="#ppd_attr_t"><code>ppd_attr_t</code></a> 207*5e7646d2SAndroid Build Coastguard Workerstructure. If you provide a NULL specifier string, all attributes with the 208*5e7646d2SAndroid Build Coastguard Workergiven name will be returned. For example, the following code lists all of the 209*5e7646d2SAndroid Build Coastguard Worker<code>Product</code> attributes in a PPD file:</p> 210*5e7646d2SAndroid Build Coastguard Worker 211*5e7646d2SAndroid Build Coastguard Worker<pre class="example"> 212*5e7646d2SAndroid Build Coastguard Worker#include <cups/ppd.h> 213*5e7646d2SAndroid Build Coastguard Worker 214*5e7646d2SAndroid Build Coastguard Worker<a href="#ppd_file_t">ppd_file_t</a> *ppd; 215*5e7646d2SAndroid Build Coastguard Worker<a href="#ppd_attr_t">ppd_attr_t</a> *attr; 216*5e7646d2SAndroid Build Coastguard Worker 217*5e7646d2SAndroid Build Coastguard Workerfor (attr = <a href="#ppdFindAttr">ppdFindAttr</a>(ppd, "Product", NULL); 218*5e7646d2SAndroid Build Coastguard Worker attr != NULL; 219*5e7646d2SAndroid Build Coastguard Worker attr = <a href="#ppdFindNextAttr">ppdFindNextAttr</a>(ppd, "Product", NULL)) 220*5e7646d2SAndroid Build Coastguard Worker puts(attr->value); 221*5e7646d2SAndroid Build Coastguard Worker</pre> 222