1 <!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
3 <!-- SECTION: Programming -->
5 <title>Introduction to CUPS Programming
</title>
6 <meta name=
"keywords" content=
"Programming">
7 <meta name=
"creator" content=
"Mini-XML v2.6">
8 <style type=
"text/css"><!--
10 font-family: lucida grande, geneva, helvetica, arial, sans-serif;
13 H1, H2, H3, H4, H5, H6, P, TD, TH {
14 font-family: lucida grande, geneva, helvetica, arial, sans-serif;
18 font-family: monaco, courier, monospace;
23 font-family: monaco, courier, monospace;
27 border: dotted thin #7f7f7f;
43 border: dotted thin #999999;
48 PRE.command EM, PRE.example EM {
49 font-family: lucida grande, geneva, helvetica, arial, sans-serif;
53 font-family: monaco, courier, monospace;
64 border: solid thin #999999;
75 -moz-border-radius: 10px;
80 text-decoration: none;
83 A:link:hover, A:visited:hover, A:active {
84 text-decoration: underline;
91 TR.data, TD.data, TR.data TD {
94 border-bottom: solid 1pt #999999;
98 border-bottom: solid 1pt #999999;
105 border: solid thin #999999;
106 border-collapse: collapse;
122 border: solid thin #cccccc;
129 border-bottom: solid thin #999999;
138 caption-side: bottom;
162 border: thin solid black;
170 H2 SPAN.info, H3 SPAN.info, H4 SPAN.info {
179 border-bottom: solid 2pt #000000;
182 DIV.indent, TABLE.indent {
190 border-collapse: collapse;
193 TABLE.indent TD, TABLE.indent TH {
198 border-collapse: collapse;
206 border-bottom: solid thin #cccccc;
211 vertical-align: bottom;
220 border-bottom: solid thin #eeeeee;
225 TABLE.list TR:nth-child(even) {
229 TABLE.list TR:nth-child(odd) {
248 font-family: monaco, courier, monospace;
252 border: solid thin #999999;
253 border-collapse: collapse;
258 DIV.summary TABLE TD, DIV.summary TABLE TH {
259 border: solid thin #999999;
265 DIV.summary TABLE THEAD TH {
269 /* API documentation styles... */
276 div.body h3, div.body h4, div.body h5 {
277 margin-bottom: 0.5em;
280 .class, .enumeration, .function, .struct, .typedef, .union {
281 border-bottom: solid thin #999999;
288 code, p.code, pre, ul.code li {
289 font-family: monaco, courier, monospace;
292 ul.code, ul.contents, ul.subcontents {
293 list-style-type: none;
303 ul.contents li ul.code, ul.contents li ul.subcontents {
316 margin-bottom: 0.5em;
319 /* This is just for the HTML files generated with the framedhelp target */
322 border: solid thin black;
331 div.contents ul.contents {
334 div.contents ul.subcontents li {
345 Introduction to CUPS programming header for the Common UNIX Printing System
348 Copyright 2008-2009 by Apple Inc.
350 These coded instructions, statements, and computer programs are the
351 property of Apple Inc. and are protected by Federal copyright
352 law. Distribution and use rights are outlined in the file "LICENSE.txt"
353 which should have been included with this file. If this file is
354 file is missing or damaged, see the license at "http://www.cups.org/".
357 <h1 class='title'
>Introduction to CUPS Programming
</h1>
359 <div class='summary'
><table summary='General Information'
>
370 cups/sidechannel.h
</th>
381 <td>Programming:
<a href='raster-driver.html' target='_top'
>Developing Raster Printer Drivers
</a><br>
382 Programming:
<a href='postscript-driver.html' target='_top'
>Developing PostScript Printer Drivers
</a><br>
383 Programming:
<a href='api-filter.html' target='_top'
>Filter and Backend Programming
</a><br>
384 Programming:
<a href='ppd-compiler.html' target='_top'
>Introduction to the PPD Compiler
</a><br>
385 Programming:
<a href='api-array.html' target='_top'
>Array API
</a><br>
386 Programming:
<a href='api-cups.html' target='_top'
>CUPS API
</a><br>
387 Programming:
<a href='api-filedir.html' target='_top'
>File and Directory APIs
</a><br>
388 Programming:
<a href='api-httpipp.html' target='_top'
>HTTP and IPP APIs
</a><br>
389 Programming:
<a href='api-ppd.html' target='_top'
>PPD API
</a><br>
390 Programming:
<a href='api-raster.html' target='_top'
>Raster API
</a><br>
391 References:
<a href='ref-ppdcfile.html' target='_top'
>PPD Compiler Driver Information File Reference
</a><br>
392 Specifications:
<a href='spec-ppd.html' target='_top'
>CUPS PPD Extensions
</a></td>
396 <h2 class=
"title">Contents
</h2>
397 <ul class=
"contents">
398 <ul class=
"subcontents">
399 <li><a href=
"#OVERVIEW">Overview
</a></li>
400 <li><a href=
"#COMPILING">Compiling Programs
</a><ul class=
"subcontents">
401 <li><a href=
"#XCODE">Compiling with Xcode
</a></li>
402 <li><a href=
"#COMMANDLINE">Compiling with GCC
</a></li>
404 <li><a href=
"#WHERETOGO">Where to Go Next
</a></li>
408 Introduction to CUPS programming content for the Common UNIX Printing System
411 Copyright 2008 by Apple Inc.
413 These coded instructions, statements, and computer programs are the
414 property of Apple Inc. and are protected by Federal copyright
415 law. Distribution and use rights are outlined in the file "LICENSE.txt"
416 which should have been included with this file. If this file is
417 file is missing or damaged, see the license at "http://www.cups.org/".
420 <h2 class=
"title"><a name=
"OVERVIEW">Overview
</a></h2>
422 <p>CUPS provides two libraries that interface with the different parts of the
423 printing system. The
"cups" library provides all of the common application and
424 filter functions while the
"cupsimage" library provides all of the imaging
425 functions used in raster printer drivers. The
"cups" library functions are
426 accessed by including the
<var><cups/cups.h
></var> header, while
427 "cupsimage" functions are found in the
<var><cups/raster.h
></var>
430 <h2 class=
"title"><a name=
"COMPILING">Compiling Programs
</a></h2>
432 <p>The CUPS libraries can be used from any C, C++, or Objective C program.
433 The method of compiling against the libraries varies depending on the
434 operating system and installation of CUPS. The following sections show how
435 to compile a simple program (shown below) in two common environments.
</p>
437 <p>The following simple program lists the available printers on the system:
</p>
439 <pre class=
"example">
440 #include
<stdio.h
>
441 #include
<cups/cups.h
>
446 cups_dest_t *dests, *dest;
447 int num_dests = cupsGetDests(
&dests);
449 for (i = num_dests, dest = dests; i
> 0; i --, dest ++)
452 printf(
"%s/%s\n", dest-
>name, dest-
>instance);
461 <h3><a name=
"XCODE">Compiling with Xcode
</a></h3>
463 <p>In Xcode, choose
<var>New Project...
</var> from the
<var>File
</var> menu,
464 then select the
<var>Standard Tool
</var> project type under
<var>Command Line
465 Utility
</var>. Click
<var>Next
</var> and choose a project directory. Click
466 <var>Next
</var> to create the project.
</p>
468 <p>In the project window, double-click on the
<var>Targets
</var> group and
469 control-click on the simple target to show the context menu. Choose
470 <var>Existing Framework...
</var> from the
<var>Add
</var> submenu. When the file
471 chooser sheet appears, press the
<kbd>/
</kbd> key and enter
"/usr/lib". Scroll
472 down the file list and select the
<var>libcups.dylib
</var> file. Click the
473 <var>Add
</var> button in the file chooser and attributes sheets.
</p>
475 <p>In the project window, double-click on the
<var>main.c
</var> source file.
476 Replace the template source code with the listing above and save it. Click the
477 <var>Build and Go
</var> button to build the sample program and run it.
</p>
479 <h3><a name=
"COMMANDLINE">Compiling with GCC
</a></h3>
481 <p>From the command-line, create a file called
<var>sample.c
</var> using your
482 favorite editor and then run the following command to compile it with GCC and
485 <pre class=
"command">
486 gcc -o simple `cups-config --cflags` simple.c `cups-config --libs`
490 <p>The
<code>cups-config
</code> command provides the compiler flags
491 (
"cups-config --cflags") and libraries (
"cups-config --libs") needed for the
494 <h2 class=
"title"><a name=
"WHERETOGO">Where to Go Next
</a></h2>
496 <p>If you are developing a print filter, driver, or backend, see the
497 <a href=
"api-filter.html" target=
"_top">Filter and Backend Programming
</a>
498 guide. Raster printer driver developers should also read the
499 <a href=
"api-raster.html" target=
"_top">Raster API
</a> reference.
</p>