• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<!DOCTYPE html>
2<html lang="en-US">
3<!-- SECTION: Programming -->
4<head>
5<title>Developing Raster Printer Drivers</title>
6<meta name="keywords" content="Programming">
7<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
8<meta name="generator" content="codedoc v3.7">
9<meta name="author" content="Unknown">
10<meta name="language" content="en-US">
11<meta name="copyright" content="Unknown">
12<meta name="version" content="0.0">
13<style type="text/css"><!--
14body {
15  background: white;
16  color: black;
17  font-family: sans-serif;
18  font-size: 12pt;
19}
20a {
21  color: black;
22}
23a:link, a:visited {
24  color: #00f;
25}
26a:link:hover, a:visited:hover, a:active {
27  color: #c0c;
28}
29body, p, h1, h2, h3, h4, h5, h6 {
30  font-family: sans-serif;
31  line-height: 1.4;
32}
33h1, h2, h3, h4, h5, h6 {
34  font-weight: bold;
35  page-break-inside: avoid;
36}
37h1 {
38  font-size: 250%;
39  margin: 0;
40}
41h2 {
42  font-size: 250%;
43  margin-top: 1.5em;
44}
45h3 {
46  font-size: 200%;
47  margin-bottom: 0.5em;
48  margin-top: 1.5em;
49}
50h4 {
51  font-size: 150%;
52  margin-bottom: 0.5em;
53  margin-top: 1.5em;
54}
55h5 {
56  font-size: 125%;
57  margin-bottom: 0.5em;
58  margin-top: 1.5em;
59}
60h6 {
61  font-size: 110%;
62  margin-bottom: 0.5em;
63  margin-top: 1.5em;
64}
65img.title {
66  width: 256px;
67}
68div.header h1, div.header p {
69  text-align: center;
70}
71div.contents, div.body, div.footer {
72  page-break-before: always;
73}
74.class, .enumeration, .function, .struct, .typedef, .union {
75  border-bottom: solid 2px gray;
76}
77.description {
78  margin-top: 0.5em;
79}
80.function {
81  margin-bottom: 0;
82}
83blockquote {
84  border: solid thin gray;
85  box-shadow: 3px 3px 5px rgba(127,127,127,0.25);
86  margin: 1em 0;
87  padding: 10px;
88  page-break-inside: avoid;
89}
90p code, li code, p.code, pre, ul.code li {
91  font-family: monospace;
92  hyphens: manual;
93  -webkit-hyphens: manual;
94}
95p.code, pre, ul.code li {
96  background: rgba(127,127,127,0.25);
97  border: thin dotted gray;
98  padding: 10px;
99  page-break-inside: avoid;
100}
101pre {
102  white-space: pre-wrap;
103}
104a:link, a:visited {
105  text-decoration: none;
106}
107span.info {
108  background: black;
109  border: solid thin black;
110  color: white;
111  font-size: 80%;
112  font-style: italic;
113  font-weight: bold;
114  white-space: nowrap;
115}
116h1 span.info, h2 span.info, h3 span.info, h4 span.info {
117  border-top-left-radius: 10px;
118  border-top-right-radius: 10px;
119  float: right;
120  padding: 3px 6px;
121}
122ul.code, ul.contents, ul.subcontents {
123  list-style-type: none;
124  margin: 0;
125  padding-left: 0;
126}
127ul.code li {
128  margin: 0;
129}
130ul.contents > li {
131  margin-top: 1em;
132}
133ul.contents li ul.code, ul.contents li ul.subcontents {
134  padding-left: 2em;
135}
136table {
137  border-collapse: collapse;
138  border-spacing: 0;
139}
140td {
141  border: solid 1px gray;
142  padding: 5px 10px;
143  vertical-align: top;
144}
145td.left {
146  text-align: left;
147}
148td.center {
149  text-align: center;
150}
151td.right {
152  text-align: right;
153}
154th {
155  border-bottom: solid 2px gray;
156  padding: 1px 5px;
157  text-align: center;
158  vertical-align: bottom;
159}
160tr:nth-child(even) {
161  background: rgba(127,127,127,0.25);
162}
163table.list {
164  border-collapse: collapse;
165  width: 100%;
166}
167table.list th {
168  border-bottom: none;
169  border-right: 2px solid gray;
170  font-family: monospace;
171  font-weight: normal;
172  padding: 5px 10px 5px 2px;
173  text-align: right;
174  vertical-align: top;
175}
176table.list td {
177  border: none;
178  padding: 5px 2px 5px 10px;
179  text-align: left;
180  vertical-align: top;
181}
182h2.title, h3.title {
183  border-bottom: solid 2px gray;
184}
185/* Syntax highlighting */
186span.comment {
187  color: darkgreen;
188}
189span.directive {
190  color: purple;
191}
192span.number {
193  color: brown;
194}
195span.reserved {
196  color: darkcyan;
197}
198span.string {
199  color: magenta;
200}
201/* Dark mode overrides */
202@media (prefers-color-scheme: dark) {
203  body {
204    background: black;
205    color: #ccc;
206  }
207  a {
208    color: #ccc;
209  }
210  a:link, a:visited {
211    color: #66f;
212  }
213  a:link:hover, a:visited:hover, a:active {
214    color: #f06;
215  }
216}
217/* Show contents on left side in web browser */
218@media screen and (min-width: 800px) {
219  div.contents {
220    border-right: solid thin gray;
221    bottom: 0px;
222    box-shadow: 3px 3px 5px rgba(127,127,127,0.5);
223    font-size: 10pt;
224    left: 0px;
225    overflow: scroll;
226    padding: 1%;
227    position: fixed;
228    top: 0px;
229    width: 18%;
230  }
231  div.contents h2.title {
232    margin-top: 0px;
233  }
234  div.header, div.body, div.footer {
235    margin-left: 20%;
236    padding: 1% 2%;
237  }
238}
239/* Center title page content vertically */
240@media print {
241  div.header {
242    padding-top: 33%;
243  }
244}
245--></style>
246</head>
247<body>
248<div class="header">
249<!--
250  Raster printer driver documentation for CUPS.
251
252  Copyright © 2020-2024 by OpenPrinting.
253  Copyright © 2007-2018 by Apple Inc.
254  Copyright © 1997-2007 by Easy Software Products.
255
256  Licensed under Apache License v2.0.  See the file "LICENSE" for more
257  information.
258-->
259
260<h1 class='title'>Developing Raster Printer Drivers</h1>
261
262<p>This document describes how to develop printer drivers for raster printers. Topics include: <a href='#BASICS'>printer driver basics</a>, <a href='#CREATE'>creating new PPD files</a>, <a href='#FILTERS'>using filters</a>, <a href='#COLOR'>implementing color management</a>, and <a href='#MACOSX'>adding macOS features</a>.</p>
263
264<div class='summary'><table summary='General Information'>
265<tbody>
266<tr>
267	<th>See Also</th>
268	<td>Programming: <a href='postscript-driver.html'>Developing PostScript Printer Drivers</a><br>
269	Programming: <a href='api-filter.html'>Filter and Backend Programming</a><br>
270	Programming: <a href='ppd-compiler.html'>Introduction to the PPD Compiler</a><br>
271	Programming: <a href='api-raster.html'>Raster API</a><br>
272	References: <a href='ref-ppdcfile.html'>PPD Compiler Driver Information File Reference</a><br>
273	Specifications: <a href='spec-ppd.html'>CUPS PPD Extensions</a></td>
274</tr>
275</tbody>
276</table></div>
277</div>
278<div class="contents">
279<h2 class="title">Contents</h2>
280<ul class="contents">
281<li><a href="#BASICS">Printer Driver Basics</a></li>
282<li><a href="#CREATING">Creating New PPD Files</a></li>
283<li><a href="#FILTERS">Using Filters</a></li>
284<li><a href="#COLOR">Implementing Color Management</a></li>
285<li><a href="#MACOSX">Adding macOS Features</a></li>
286</ul>
287</div>
288<div class="body">
289<h2 class='title'><a name='BASICS'>Printer Driver Basics</a></h2>
290
291<p>A CUPS raster printer driver consists of a PostScript Printer Description (PPD) file that describes the features and capabilities of the device, one or more <em>filter</em> programs that prepare print data for the device, and zero or more support files for color management, online help, and so forth. The PPD file includes references to all of the filters and support files used by the driver.</p>
292
293<p>Every time a user prints something the scheduler program, <a href='man-cupsd.html'>cupsd(8)</a>, determines the format of the print job and the programs required to convert that job into something the printer understands. CUPS includes filter programs for many common formats, for example to convert Portable Document Format (PDF) files into CUPS raster data. <a href='#FIGURE_1'>Figure 1</a> shows the data flow of a typical print job.</p>
294
295<div class='figure'><table summary='Raster Filter Chain'>
296<caption>Figure 1: <a name='FIGURE_1'>Raster Filter Chain</a></caption>
297<tr><td><img src='../images/cups-raster-chain.png' width='700' height='150' alt='Raster Filter Chain'></td></tr>
298</table></div>
299
300<p>The raster filter converts CUPS raster data into a format the printer understands, for example HP-PCL. CUPS includes several sample raster filters supporting standard page description languages (PDLs). <a href='#TABLE_1'>Table 1</a> shows the raster filters that are bundled with CUPS and the languages they support.</p>
301
302<div class='table'><table summary='Standard CUPS Raster Filters'>
303<caption>Table 1: <a name='TABLE_1'>Standard CUPS Raster Filters</a></caption>
304<thead>
305<tr><th>Filter</th><th>PDLs</th><th>ppdc DriverType</th><th>ppdc #include file</th></tr>
306</thead>
307<tbody>
308<tr><td>rastertoepson</td><td>ESC/P, ESC/P2</td><td>epson</td><td>epson.h</td></tr>
309<tr><td>rastertoescpx</td><td>ESC/P, ESC/P2, EPSON Remote Mode</td><td>escp</td><td>escp.h</td></tr>
310<tr><td>rastertohp</td><td>HP-PCL3, HP-PCL5</td><td>hp</td><td>hp.h</td></tr>
311<tr><td>rastertolabel</td><td>CPCL, Dymo, EPL1, EPL2, Intellitech PCL, ZPL</td><td>label</td><td>label.h</td></tr>
312<tr><td>rastertopclx</td><td>HP-RTL, HP-PCL3, HP-PCL3GUI, HP-PCL5, HP-PCL5c, HP-PCL5e</td><td>pcl</td><td>pcl.h</td></tr>
313</tbody>
314</table></div>
315
316<p>The optional port monitor handles interface-specific protocol or encoding issues. For example, some raster printers use the 1284.4 communications protocol.</p>
317
318<p>The backend handles communications with the printer, sending print data from the last filter to the printer and relaying back-channel data from the printer to the upstream filters. CUPS includes backend programs for common direct-connect interfaces and network protocols, and you can provide your own backend to support custom interfaces and protocols.</p>
319
320<p>The scheduler also supports a special "command" file format for sending maintenance commands and status queries to a printer or printer driver. Command print jobs typically use a single command filter program defined in the PPD file to generate the appropriate printer commands and handle any responses from the printer. <a href='#FIGURE_2'>Figure 2</a> shows the data flow of a typical command job.</p>
321
322<div class='figure'><table summary='Command Filter Chain'>
323<caption>Figure 2: <a name='FIGURE_2'>Command Filter Chain</a></caption>
324<tr><td><img src='../images/cups-command-chain.png' width='575' height='150' alt='Command Filter Chain'></td></tr>
325</table></div>
326
327<p>Raster printer drivers must provide their own command filter.</p>
328
329
330<h2 class='title'><a name='CREATING'>Creating New PPD Files</a></h2>
331
332<p>We recommend using the CUPS PPD compiler, <a href='man-ppdc.html'>ppdc(1)</a>, to create new PPD files since it manages many of the tedious (and error-prone!) details of paper sizes and localization for you. It also allows you to easily support multiple devices from a single source file. For more information see the "<a href='ppd-compiler.html'>Introduction to the PPD Compiler</a>" document. <a href='#LISTING_1'>Listing 1</a> shows a driver information file for several similar black-and-white HP-PCL5 laser printers.</p>
333
334<p class='example'>Listing 1: <a name='LISTING_1'>"examples/laserjet-basic.drv"</a></p>
335
336<pre class='example'>
337<I>// Include standard font and media definitions</I>
338<a href='ref-ppdcfile.html#_include'>#include</a> &lt;font.defs&gt;
339<a href='ref-ppdcfile.html#_include'>#include</a> &lt;media.defs&gt;
340
341<I>// Include HP-PCL driver definitions</I>
342<a href='ref-ppdcfile.html#_include'>#include</a> &lt;pcl.h&gt;
343
344<I>// Specify that this driver uses the HP-PCL driver...</I>
345<a href='ref-ppdcfile.html#DriverType'>DriverType</a> pcl
346
347<I>// Specify the driver options via the model number...</I>
348<a href='ref-ppdcfile.html#ModelNumber'>ModelNumber</a> ($PCL_PAPER_SIZE $PCL_PJL $PCL_PJL_RESOLUTION)
349
350<I>// List the fonts that are supported, in this case all standard fonts...</I>
351<a href='ref-ppdcfile.html#Font'>Font</a> *
352
353<I>// Manufacturer and driver version</I>
354<a href='ref-ppdcfile.html#Manufacturer'>Manufacturer</a> "HP"
355<a href='ref-ppdcfile.html#Version'>Version</a> 1.0
356
357<I>// Supported page sizes and their margins</I>
358<a href='ref-ppdcfile.html#HWMargins'>HWMargins</a> 18 12 18 12
359*<a href='ref-ppdcfile.html#MediaSize'>MediaSize</a> Letter
360<a href='ref-ppdcfile.html#MediaSize'>MediaSize</a> Legal
361<a href='ref-ppdcfile.html#MediaSize'>MediaSize</a> Executive
362<a href='ref-ppdcfile.html#MediaSize'>MediaSize</a> Monarch
363<a href='ref-ppdcfile.html#MediaSize'>MediaSize</a> Statement
364<a href='ref-ppdcfile.html#MediaSize'>MediaSize</a> FanFoldGermanLegal
365
366<a href='ref-ppdcfile.html#HWMargins'>HWMargins</a> 18 12.72 18 12.72
367<a href='ref-ppdcfile.html#MediaSize'>MediaSize</a> Env10
368
369<a href='ref-ppdcfile.html#HWMargins'>HWMargins</a> 9.72 12 9.72 12
370<a href='ref-ppdcfile.html#MediaSize'>MediaSize</a> A4
371<a href='ref-ppdcfile.html#MediaSize'>MediaSize</a> A5
372<a href='ref-ppdcfile.html#MediaSize'>MediaSize</a> B5
373<a href='ref-ppdcfile.html#MediaSize'>MediaSize</a> EnvC5
374<a href='ref-ppdcfile.html#MediaSize'>MediaSize</a> EnvDL
375<a href='ref-ppdcfile.html#MediaSize'>MediaSize</a> EnvISOB5
376<a href='ref-ppdcfile.html#MediaSize'>MediaSize</a> Postcard
377<a href='ref-ppdcfile.html#MediaSize'>MediaSize</a> DoublePostcard
378
379<I>// Only black-and-white output with mode 3 compression...</I>
380<a href='ref-ppdcfile.html#ColorModel'>ColorModel</a> Gray k chunky 3
381
382<I>// Supported resolutions</I>
383<a href='ref-ppdcfile.html#Resolution'>Resolution</a> - 1 0 0 0 "300dpi/300 DPI"
384*<a href='ref-ppdcfile.html#Resolution'>Resolution</a> - 8 0 0 0 "600dpi/600 DPI"
385
386<I>// Supported input slots</I>
387*<a href='ref-ppdcfile.html#InputSlot'>InputSlot</a> 7 "Auto/Automatic Selection"
388<a href='ref-ppdcfile.html#InputSlot'>InputSlot</a> 2 "Manual/Tray 1 - Manual Feed"
389<a href='ref-ppdcfile.html#InputSlot'>InputSlot</a> 4 "Upper/Tray 1"
390<a href='ref-ppdcfile.html#InputSlot'>InputSlot</a> 1 "Lower/Tray 2"
391<a href='ref-ppdcfile.html#InputSlot'>InputSlot</a> 5 "LargeCapacity/Tray 3"
392
393<I>// Tray 3 is an option...</I>
394<a href='ref-ppdcfile.html#Installable'>Installable</a> "OptionLargeCapacity/Tray 3 Installed"
395<a href='ref-ppdcfile.html#UIConstraints'>UIConstraints</a> "*OptionLargeCapacity False *InputSlot LargeCapacity"
396
397{
398  <I>// HP LaserJet 2100 Series</I>
399  <a href='ref-ppdcfile.html#Throughput'>Throughput</a> 10
400  <a href='ref-ppdcfile.html#ModelName'>ModelName</a> "LaserJet 2100 Series"
401  <a href='ref-ppdcfile.html#PCFileName'>PCFileName</a> "hpljt211.ppd"
402}
403
404{
405  <I>// LaserJet 2200 and 2300 series have duplexer option...</I>
406  <a href='ref-ppdcfile.html#Duplex'>Duplex</a> normal
407  <a href='ref-ppdcfile.html#Installable'>Installable</a> "OptionDuplex/Duplexer Installed"
408  <a href='ref-ppdcfile.html#UIConstraints'>UIConstraints</a> "*OptionDuplex False *Duplex"
409
410  {
411    <I>// HP LaserJet 2200 Series</I>
412    <a href='ref-ppdcfile.html#Throughput'>Throughput</a> 19
413    <a href='ref-ppdcfile.html#ModelName'>ModelName</a> "LaserJet 2200 Series"
414    <a href='ref-ppdcfile.html#PCFileName'>PCFileName</a> "hpljt221.ppd"
415  }
416
417  {
418    <I>// HP LaserJet 2300 Series</I>
419    <a href='ref-ppdcfile.html#Throughput'>Throughput</a> 25
420    <a href='ref-ppdcfile.html#ModelName'>ModelName</a> "LaserJet 2300 Series"
421    <a href='ref-ppdcfile.html#PCFileName'>PCFileName</a> "hpljt231.ppd"
422  }
423}
424</pre>
425
426
427<h2 class='title'><a name='FILTERS'>Using Filters</a></h2>
428
429<p>The standard CUPS raster filters can be specified using the
430<a href='ref-ppdcfile.html#DriverType'><tt>DriverType</tt></a> directive, for example:</p>
431
432<pre class='example'>
433<I>// Specify that this driver uses the HP-PCL driver...</I>
434<a href='ref-ppdcfile.html#DriverType'>DriverType</a> pcl
435</pre>
436
437<p><a href='#TABLE_1'>Table 1</a> shows the driver types for each of the standard CUPS raster filters. For drivers that do not use the standard raster filters, the "custom" type is used with <a href='ref-ppdcfile.html#Filter'><tt>Filter</tt></a> directives:</p>
438
439<pre class='example'>
440<a href='ref-ppdcfile.html#DriverType'>DriverType</a> custom
441<a href='ref-ppdcfile.html#Filter'>Filter</a> application/vnd.cups-raster 100 /path/to/raster/filter
442<a href='ref-ppdcfile.html#Filter'>Filter</a> application/vnd.cups-command 100 /path/to/command/filter
443</pre>
444
445
446<h2 class='title'><a name='COLOR'>Implementing Color Management</a></h2>
447
448<p>CUPS uses ICC color profiles to provide more accurate color reproduction. The <a href='spec-ppd.html#cupsICCProfile'><tt>cupsICCProfile</tt></a> attribute defines the color profiles that are available for a given printer, for example:</p>
449
450<pre class='example'>
451<a href='ref-ppdcfile.html#Attribute'>Attribute</a> cupsICCProfile "ColorModel.MediaType.Resolution/Description" /path/to/ICC/profile
452</pre>
453
454<p>where "ColorModel.MediaType.Resolution" defines a selector based on the corresponding option selections. A simple driver might only define profiles for the color models that are supported, for example a printer supporting Gray and RGB might use:</p>
455
456<pre class='example'>
457<a href='ref-ppdcfile.html#Attribute'>Attribute</a> cupsICCProfile "Gray../Grayscale Profile" /path/to/ICC/gray-profile
458<a href='ref-ppdcfile.html#Attribute'>Attribute</a> cupsICCProfile "RGB../Full Color Profile" /path/to/ICC/rgb-profile
459</pre>
460
461<p>The options used for profile selection can be customized using the <tt>cupsICCQualifier2</tt> and <tt>cupsICCQualifier3</tt> attributes.</p>
462
463<h3><span class='info'>Since macOS 10.5</span>Custom Color Matching Support</h3>
464
465<p>macOS printer drivers that are based on an existing standard RGB colorspace can tell the system to use the corresponding colorspace instead of an arbitrary ICC color profile when doing color management. The <a href='#APCustom'><tt>APSupportsCustomColorMatching</tt></a> and <tt>APDefaultCustomColorMatchingProfile</tt> attributes can be used to enable this mode:</p>
466
467<pre class='example'>
468<a href='ref-ppdcfile.html#Attribute'>Attribute</a> APSupportsCustomColorMatching "" true
469<a href='ref-ppdcfile.html#Attribute'>Attribute</a> APDefaultCustomColorMatchingProfile "" sRGB
470</pre>
471
472
473<h2 class='title'><a name='MACOSX'>Adding macOS Features</a></h2>
474
475<p>macOS printer drivers can provide <a href='spec-ppd.html#MACOSX'>additional attributes</a> to specify additional option panes in the print dialog, an image of the printer, a help book, and option presets for the driver software:</p>
476
477<pre class='example'>
478<a href='ref-ppdcfile.html#Attribute'>Attribute</a> APDialogExtension "" /Library/Printers/Vendor/filename.plugin
479<a href='ref-ppdcfile.html#Attribute'>Attribute</a> APHelpBook "" /Library/Printers/Vendor/filename.bundle
480<a href='ref-ppdcfile.html#Attribute'>Attribute</a> APPrinterIconPath "" /Library/Printers/Vendor/filename.icns
481<a href='ref-ppdcfile.html#Attribute'>Attribute</a> APPrinterPreset "name/text" "*option choice ..."
482</pre>
483</div>
484</body>
485</html>
486