]> git.ipfire.org Git - thirdparty/cups.git/blame - doc/help/api-overview.html
Merge changes from CUPS 1.5svn-r9717.
[thirdparty/cups.git] / doc / help / api-overview.html
CommitLineData
745129be 1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
5a738aea
MS
2<html>
3<!-- SECTION: Programming -->
4<head>
0268488e
MS
5 <title>Introduction to CUPS Programming </title>
6 <meta name="keywords" content="Programming">
7 <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
8 <meta name="creator" content="Mini-XML v2.7">
5a738aea
MS
9<style type="text/css"><!--
10BODY {
11 font-family: lucida grande, geneva, helvetica, arial, sans-serif;
12}
13
14H1, H2, H3, H4, H5, H6, P, TD, TH {
15 font-family: lucida grande, geneva, helvetica, arial, sans-serif;
16}
17
18KBD {
19 font-family: monaco, courier, monospace;
20 font-weight: bold;
21}
22
23PRE {
24 font-family: monaco, courier, monospace;
25}
26
27PRE.command {
10d09e33 28 border: dotted thin #7f7f7f;
5a738aea 29 margin-left: 36pt;
10d09e33 30 padding: 10px;
5a738aea
MS
31}
32
f11a948a
MS
33P.compact {
34 margin: 0;
35}
36
e4572d57
MS
37P.example {
38 font-style: italic;
39 margin-left: 36pt;
40}
41
5a738aea
MS
42PRE.example {
43 background: #eeeeee;
44 border: dotted thin #999999;
45 margin-left: 36pt;
178cb736 46 padding: 10pt;
5a738aea
MS
47}
48
49PRE.command EM, PRE.example EM {
50 font-family: lucida grande, geneva, helvetica, arial, sans-serif;
51}
52
53P.command {
54 font-family: monaco, courier, monospace;
55 margin-left: 36pt;
56}
57
58P.formula {
59 font-style: italic;
60 margin-left: 36pt;
61}
62
63BLOCKQUOTE {
178cb736 64 background: #eeeeee;
5a738aea
MS
65 border: solid thin #999999;
66 padding: 10pt;
67}
68
e4572d57
MS
69A IMG {
70 border: none;
71}
72
73A:link:hover IMG {
74 background: #f0f0f0;
75 border-radius: 10px;
76 -moz-border-radius: 10px;
77}
78
5a738aea 79A:link, A:visited {
568fa3fa 80 font-weight: normal;
5a738aea 81 text-decoration: none;
5a738aea
MS
82}
83
84A:link:hover, A:visited:hover, A:active {
85 text-decoration: underline;
5a738aea
MS
86}
87
88SUB, SUP {
89 font-size: 50%;
90}
91
e4572d57
MS
92TR.data, TD.data, TR.data TD {
93 margin-top: 10pt;
94 padding: 5pt;
95 border-bottom: solid 1pt #999999;
96}
97
98TR.data TH {
99 border-bottom: solid 1pt #999999;
100 padding-top: 10pt;
101 padding-left: 5pt;
102 text-align: left;
103}
104
5a738aea
MS
105DIV.table TABLE {
106 border: solid thin #999999;
107 border-collapse: collapse;
108 border-spacing: 0;
109 margin-left: auto;
110 margin-right: auto;
111}
112
113DIV.table CAPTION {
114 caption-side: top;
115 font-size: 120%;
116 font-style: italic;
117 font-weight: bold;
118 margin-left: auto;
119 margin-right: auto;
120}
121
122DIV.table TABLE TD {
123 border: solid thin #cccccc;
124 padding-top: 5pt;
125}
126
127DIV.table TABLE TH {
128 background: #cccccc;
129 border: none;
130 border-bottom: solid thin #999999;
131}
132
133DIV.figure TABLE {
134 margin-left: auto;
135 margin-right: auto;
136}
137
138DIV.figure CAPTION {
139 caption-side: bottom;
140 font-size: 120%;
141 font-style: italic;
142 font-weight: bold;
143 margin-left: auto;
144 margin-right: auto;
145}
146
147TH.label {
5a738aea
MS
148 text-align: right;
149 vertical-align: top;
150}
151
e4572d57
MS
152TH.sublabel {
153 text-align: right;
154 font-weight: normal;
155}
156
5a738aea
MS
157HR {
158 border: solid thin;
159}
160
161SPAN.info {
e4572d57
MS
162 background: black;
163 border: thin solid black;
164 color: white;
5a738aea
MS
165 font-size: 80%;
166 font-style: italic;
167 font-weight: bold;
168 white-space: nowrap;
169}
170
171H2 SPAN.info, H3 SPAN.info, H4 SPAN.info {
172 float: right;
173 font-size: 100%;
174}
175
178cb736
MS
176H1.title {
177}
178
5a738aea
MS
179H2.title, H3.title {
180 border-bottom: solid 2pt #000000;
181}
182
e4572d57
MS
183DIV.indent, TABLE.indent {
184 margin-top: 2em;
185 margin-left: auto;
186 margin-right: auto;
187 width: 90%;
188}
189
190TABLE.indent {
191 border-collapse: collapse;
192}
193
194TABLE.indent TD, TABLE.indent TH {
195 padding: 0;
196}
197
198TABLE.list {
199 border-collapse: collapse;
200 margin-left: auto;
201 margin-right: auto;
202 width: 90%;
203}
204
205TABLE.list TH {
206 background: white;
207 border-bottom: solid thin #cccccc;
208 color: #444444;
209 padding-top: 10pt;
210 padding-left: 5pt;
211 text-align: left;
212 vertical-align: bottom;
213 white-space: nowrap;
214}
215
216TABLE.list TH A {
217 color: #4444cc;
218}
219
220TABLE.list TD {
221 border-bottom: solid thin #eeeeee;
222 padding-top: 5pt;
223 padding-left: 5pt;
224}
225
226TABLE.list TR:nth-child(even) {
227 background: #f8f8f8;
228}
229
230TABLE.list TR:nth-child(odd) {
231 background: #f4f4f4;
232}
233
5a738aea
MS
234DT {
235 margin-left: 36pt;
236 margin-top: 12pt;
237}
238
239DD {
240 margin-left: 54pt;
241}
242
243DL.category DT {
244 font-weight: bold;
245}
246
247P.summary {
248 margin-left: 36pt;
249 font-family: monaco, courier, monospace;
250}
251
5a738aea
MS
252DIV.summary TABLE {
253 border: solid thin #999999;
254 border-collapse: collapse;
255 border-spacing: 0;
256 margin: 10px;
257}
258
259DIV.summary TABLE TD, DIV.summary TABLE TH {
260 border: solid thin #999999;
261 padding: 5px;
262 text-align: left;
263 vertical-align: top;
264}
265
266DIV.summary TABLE THEAD TH {
267 background: #eeeeee;
268}
269
270/* API documentation styles... */
271div.body h1 {
272 margin: 0;
273}
274div.body h2 {
275 margin-top: 1.5em;
276}
277div.body h3, div.body h4, div.body h5 {
278 margin-bottom: 0.5em;
279 margin-top: 1.5em;
280}
281.class, .enumeration, .function, .struct, .typedef, .union {
282 border-bottom: solid thin #999999;
283 margin-bottom: 0;
284 margin-top: 2em;
285}
286.description {
287 margin-top: 0.5em;
288}
289code, p.code, pre, ul.code li {
290 font-family: monaco, courier, monospace;
291 font-size: 90%;
292}
293ul.code, ul.contents, ul.subcontents {
294 list-style-type: none;
295 margin: 0;
296 padding-left: 0;
297}
298ul.code li {
299 margin: 0;
300}
301ul.contents > li {
302 margin-top: 1em;
303}
304ul.contents li ul.code, ul.contents li ul.subcontents {
305 padding-left: 2em;
306}
307div.body dl {
308 margin-left: 0;
309 margin-top: 0;
310}
311div.body dt {
312 font-style: italic;
313 margin-left: 0;
314 margin-top: 0;
315}
316div.body dd {
317 margin-bottom: 0.5em;
318}
319
320/* This is just for the HTML files generated with the framedhelp target */
321div.contents {
322 background: #e8e8e8;
323 border: solid thin black;
324 padding: 10px;
325}
326div.contents h1 {
327 font-size: 110%;
328}
329div.contents h2 {
330 font-size: 100%;
331}
332div.contents ul.contents {
333 font-size: 80%;
334}
ac884b6a
MS
335div.contents ul.subcontents li {
336 margin-left: 1em;
337 text-indent: -1em;
338}
5a738aea
MS
339--></style>
340</head>
341<body>
342<div class='body'>
343<!--
68b10830 344 "$Id$"
5a738aea
MS
345
346 Introduction to CUPS programming header for the Common UNIX Printing System
347 (CUPS).
348
178cb736 349 Copyright 2008-2009 by Apple Inc.
5a738aea
MS
350
351 These coded instructions, statements, and computer programs are the
352 property of Apple Inc. and are protected by Federal copyright
353 law. Distribution and use rights are outlined in the file "LICENSE.txt"
354 which should have been included with this file. If this file is
355 file is missing or damaged, see the license at "http://www.cups.org/".
356-->
357
178cb736
MS
358<h1 class='title'>Introduction to CUPS Programming</h1>
359
5a738aea
MS
360<div class='summary'><table summary='General Information'>
361<thead>
362<tr>
363 <th>Headers</th>
364 <th>cups/cups.h<br>
365 cups/array.h<br>
366 cups/backend.h<br>
367 cups/dir.h<br>
368 cups/file.h<br>
369 cups/ppd.h<br>
370 cups/raster.h<br>
371 cups/sidechannel.h</th>
372</tr>
373</thead>
374<tbody>
375<tr>
376 <th>Libraries</th>
377 <td>-lcups<br>
378 -lcupsimage</td>
379</tr>
380<tr>
381 <th>See Also</th>
e4572d57
MS
382 <td>Programming: <a href='raster-driver.html' target='_top'>Developing Raster Printer Drivers</a><br>
383 Programming: <a href='postscript-driver.html' target='_top'>Developing PostScript Printer Drivers</a><br>
384 Programming: <a href='api-filter.html' target='_top'>Filter and Backend Programming</a><br>
385 Programming: <a href='ppd-compiler.html' target='_top'>Introduction to the PPD Compiler</a><br>
5a738aea 386 Programming: <a href='api-array.html' target='_top'>Array API</a><br>
e4572d57 387 Programming: <a href='api-cups.html' target='_top'>CUPS API</a><br>
5a738aea 388 Programming: <a href='api-filedir.html' target='_top'>File and Directory APIs</a><br>
5a738aea
MS
389 Programming: <a href='api-httpipp.html' target='_top'>HTTP and IPP APIs</a><br>
390 Programming: <a href='api-ppd.html' target='_top'>PPD API</a><br>
e4572d57
MS
391 Programming: <a href='api-raster.html' target='_top'>Raster API</a><br>
392 References: <a href='ref-ppdcfile.html' target='_top'>PPD Compiler Driver Information File Reference</a><br>
393 Specifications: <a href='spec-ppd.html' target='_top'>CUPS PPD Extensions</a></td>
5a738aea
MS
394</tr>
395</tbody>
396</table></div>
397<h2 class="title">Contents</h2>
398<ul class="contents">
5a738aea
MS
399<li><a href="#OVERVIEW">Overview</a></li>
400<li><a href="#COMPILING">Compiling Programs</a><ul class="subcontents">
0268488e
MS
401 <li><a href="#XCODE">Compiling with Xcode</a></li>
402 <li><a href="#COMMANDLINE">Compiling with GCC</a></li>
8b450588 403</ul></li>
5a738aea 404<li><a href="#WHERETOGO">Where to Go Next</a></li>
0268488e 405</ul>
5a738aea 406<!--
68b10830 407 "$Id$"
5a738aea
MS
408
409 Introduction to CUPS programming content for the Common UNIX Printing System
410 (CUPS).
411
412 Copyright 2008 by Apple Inc.
413
414 These coded instructions, statements, and computer programs are the
415 property of Apple Inc. and are protected by Federal copyright
416 law. Distribution and use rights are outlined in the file "LICENSE.txt"
417 which should have been included with this file. If this file is
418 file is missing or damaged, see the license at "http://www.cups.org/".
419-->
420
421<h2 class="title"><a name="OVERVIEW">Overview</a></h2>
422
423<p>CUPS provides two libraries that interface with the different parts of the
424printing system. The "cups" library provides all of the common application and
425filter functions while the "cupsimage" library provides all of the imaging
426functions used in raster printer drivers. The "cups" library functions are
427accessed by including the <var>&lt;cups/cups.h&gt;</var> header, while
428"cupsimage" functions are found in the <var>&lt;cups/raster.h&gt;</var>
429header.</p>
430
431<h2 class="title"><a name="COMPILING">Compiling Programs</a></h2>
432
433<p>The CUPS libraries can be used from any C, C++, or Objective C program.
434The method of compiling against the libraries varies depending on the
435operating system and installation of CUPS. The following sections show how
436to compile a simple program (shown below) in two common environments.</p>
437
438<p>The following simple program lists the available printers on the system:</p>
439
440<pre class="example">
441#include &lt;stdio.h&gt;
442#include &lt;cups/cups.h&gt;
443
444int main(void)
445{
446 int i;
447 cups_dest_t *dests, *dest;
448 int num_dests = cupsGetDests(&amp;dests);
449
450 for (i = num_dests, dest = dests; i &gt; 0; i --, dest ++)
451 {
452 if (dest->instance)
453 printf("%s/%s\n", dest->name, dest->instance);
454 else
455 puts(dest->name);
456 }
457
458 return (0);
459}
460</pre>
461
462<h3><a name="XCODE">Compiling with Xcode</a></h3>
463
464<p>In Xcode, choose <var>New Project...</var> from the <var>File</var> menu,
465then select the <var>Standard Tool</var> project type under <var>Command Line
466Utility</var>. Click <var>Next</var> and choose a project directory. Click
467<var>Next</var> to create the project.</p>
468
469<p>In the project window, double-click on the <var>Targets</var> group and
470control-click on the simple target to show the context menu. Choose
471<var>Existing Framework...</var> from the <var>Add</var> submenu. When the file
472chooser sheet appears, press the <kbd>/</kbd> key and enter "/usr/lib". Scroll
473down the file list and select the <var>libcups.dylib</var> file. Click the
474<var>Add</var> button in the file chooser and attributes sheets.</p>
475
476<p>In the project window, double-click on the <var>main.c</var> source file.
477Replace the template source code with the listing above and save it. Click the
478<var>Build and Go</var> button to build the sample program and run it.</p>
479
480<h3><a name="COMMANDLINE">Compiling with GCC</a></h3>
481
482<p>From the command-line, create a file called <var>sample.c</var> using your
483favorite editor and then run the following command to compile it with GCC and
484run it:</p>
485
486<pre class="command">
487gcc -o simple `cups-config --cflags` simple.c `cups-config --libs`
488./simple
489</pre>
490
491<p>The <code>cups-config</code> command provides the compiler flags
492("cups-config --cflags") and libraries ("cups-config --libs") needed for the
493local system.</p>
494
495<h2 class="title"><a name="WHERETOGO">Where to Go Next</a></h2>
496
497<p>If you are developing a print filter, driver, or backend, see the
498<a href="api-filter.html" target="_top">Filter and Backend Programming</a>
499guide. Raster printer driver developers should also read the
500<a href="api-raster.html" target="_top">Raster API</a> reference.</p>
501</div>
502</body>
503</html>