1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 2 3<html> 4 <head> 5 <meta name="generator" content="HTML Tidy, see www.w3.org"> 6 <title>Job Options and the Z Control File Entry</title> 7 <meta name="GENERATOR" content= 8 "Modular DocBook HTML Stylesheet Version 1.7"> 9 <link rel="HOME" title=" LPRng Reference Manual" href= 10 "index.htm"> 11 <link rel="UP" title="Print Spooling Tutorial " href= 12 "tutorial.htm"> 13 <link rel="PREVIOUS" title="Routing Jobs To Print Queues" href= 14 "x3694.htm"> 15 <link rel="NEXT" title="Interfacing to Non-LPRng Spoolers" 16 href="x3885.htm"> 17 </head> 18 19 <body class="SECT1" bgcolor="#FFFFFF" text="#000000" link= 20 "#0000FF" vlink="#840084" alink="#0000FF"> 21 <div class="NAVHEADER"> 22 <table summary="Header navigation table" width="100%" border= 23 "0" cellpadding="0" cellspacing="0"> 24 <tr> 25 <th colspan="3" align="center">LPRng Reference Manual: 5 26 Sep 2003 (For LPRng-3.8.22)</th> 27 </tr> 28 29 <tr> 30 <td width="10%" align="left" valign="bottom"><a href= 31 "x3694.htm" accesskey="P">Prev</a></td> 32 33 <td width="80%" align="center" valign="bottom">Chapter 4. 34 Print Spooling Tutorial</td> 35 36 <td width="10%" align="right" valign="bottom"><a href= 37 "x3885.htm" accesskey="N">Next</a></td> 38 </tr> 39 </table> 40 <hr align="LEFT" width="100%"> 41 </div> 42 43 <div class="SECT1"> 44 <h1 class="SECT1"><a name="AEN3767">4.19. Job Options and the 45 Z Control File Entry</a></h1> 46 47 <p>Many printers have special capabilities such as printing 48 in landscape mode, duplex printing, binding, or stapling. 49 These capabilities are usually invoked or enabled by the 50 print spooler sending special printer control commands to the 51 printer based on values it finds in the control file. The <b 52 class="APPLICATION">LPRng</b> print spooler uses the <var 53 class="LITERAL">Z</var> line in the control file to specify 54 these options, while other print spoolers such as the Sun 55 Microsystems Solaris <b class="APPLICATION">lp</b> system 56 pass them on the <var class="LITERAL">S</var> line.</p> 57 58 <p>Job formatting options are specified using the <tt class= 59 "COMMAND">lpr -Z</tt> option. The <b class= 60 "APPLICATION">lpr</b> program concatenates the <var class= 61 "LITERAL">-Z</var> options and puts them in the control file 62 as a single <var class="LITERAL">Z</var> line. For 63 example:</p> 64 65 <div class="INFORMALEXAMPLE"> 66 <a name="AEN3779"></a> 67<pre class="SCREEN"> 68 <samp class="PROMPT">h4: {289} %</samp> <kbd class= 69"USERINPUT">lpc stop</kbd> 70 Printer: lp@h4 71 lp@h4.private: stopped 72 <samp class="PROMPT">h4: {290} %</samp> <kbd class= 73"USERINPUT">lpr -Zthis -Zthat /tmp/hi</kbd> 74 <samp class="PROMPT">h4: {291} %</samp> <kbd class= 75"USERINPUT">cat /var/spool/lp/cf*</kbd> 76 Hh4.private 77 Ppapowell 78 J/tmp/hi 79 CA 80 Lpapowell 81 Zthis,that 82 Apapowell@h4+115 83 D2000-05-05-10:05:41.351 84 Qlp 85 N/tmp/hi 86 fdfA115h4.private 87 UdfA115h4.private 88</pre> 89 </div> 90 <br> 91 <br> 92 93 <p>As we see, the <var class="LITERAL">Z</var> options have 94 been put into the control file on the <var class= 95 "LITERAL">Z</var> line. The <var class="LITERAL">Z</var> 96 option values are passed to filters on the command line as 97 the <var class="LITERAL">-Z</var> command line option. These 98 values are used by the <b class="APPLICATION">ifhp</b> filter 99 to determine what control commands to send to the printer and 100 how to format the print job output. Because each printer is 101 different and supports a different set of capabilities it is 102 impossible to have a set of job options supported across all 103 printers. The following are supported by the <b class= 104 "APPLICATION">ifhp</b> configuration where possible. Many of 105 these options rely on the printer supporting PostScript or 106 having the appropriate PCL commands to do the indicated 107 operation.</p> 108 109 <ul> 110 <li> 111 <p>-Zlandscape -Zportrait - select landscape or portrait 112 orientation.</p> 113 </li> 114 115 <li> 116 <p>-Zduplex -Zsimplex - select duplex (both sides of a 117 page) or simplex (single side of a page) printing.</p> 118 </li> 119 120 <li> 121 <p>-Zletter -Zlegal -Zledger -Za4 -Za5 -Zenvelope 122 -Ztransparency - select a paper size</p> 123 </li> 124 125 <li> 126 <p>-Zinupper -Zinmiddle -Zinlower - select input media 127 from the appropriate input tray</p> 128 </li> 129 130 <li> 131 <p>-Zmanual - select input from the manual feed</p> 132 </li> 133 </ul> 134 <br> 135 <br> 136 137 <div class="SECT2"> 138 <h2 class="SECT2"><a name="AEN3805">4.19.1. Setting Job 139 Options Using the Printcap</a></h2> 140 141 <p>An alternative to this method of using <b class= 142 "APPLICATION">lpr</b> and the <var class="LITERAL">-Z</var> 143 option is to define a set of spool queues which will put 144 the necessary options into the job control file. This can 145 be done by the <b class="APPLICATION">lpr</b> program when 146 the job is generated, or by the <b class= 147 "APPLICATION">lpd</b> spooler when the job is processed. 148 The The options specified by the <var class= 149 "LITERAL">:prefix_z</var>, <var class= 150 "LITERAL">:append_z</var>, and <var class= 151 "LITERAL">:delete_z</var> are prefixed, appended, or 152 deleted from the current set of <var class= 153 "LITERAL">Z</var> control file options by the <b class= 154 "APPLICATION">lpr</b> program when the job is submitted and 155 they are specified in the printcap for the queue, or by the 156 <b class="APPLICATION">lpd</b> spooler when the job is 157 submitted to the queue. We can use this capapbility to 158 configure print queues to a desired set of <var class= 159 "LITERAL">Z</var> options into the control file. For 160 example:</p> 161 162 <div class="INFORMALEXAMPLE"> 163 <a name="AEN3819"></a> 164<pre class="SCREEN"> 165 landscape:lp=%P@server 166 landscape:server:tc=.common 167 :lp=raw@server:append_z=landscape:delete_z=portrait 168 raw:server:tc=.common:lp=.... 169 :filter=/usr/local/libexec/filters/ifhp 170 .common:sd=/var/spool/lpd/%P 171</pre> 172 </div> 173 <br> 174 <br> 175 176 <p>When a job is sent to the <var class= 177 "LITERAL">landscape</var> queue, the control file <var 178 class="LITERAL">Z</var> line will have the <var class= 179 "LITERAL">portrait</var> option removed and the <var class= 180 "LITERAL">landscape</var> option appended. The <var class= 181 "LITERAL">:delete_z</var> values are glob patterns and 182 options that match are removed from the option list. 183 Options are assumed to be separated by commas or semicolons 184 in the option list.</p> 185 </div> 186 187 <div class="SECT2"> 188 <h2 class="SECT2"><a name="AEN3827">4.19.2. Converting 189 SystemV Options to LPRng Options</a></h2> 190 191 <p>On some SystemV <b class="APPLICATION">lp</b> print 192 spoolers, the <tt class="COMMAND">lp -o option</tt>, puts 193 the option information into the control file <var class= 194 "LITERAL">S</var> line, and on other systems on the puts 195 the option information into the control file <var class= 196 "LITERAL">O</var> line. To convert these options to <b 197 class="APPLICATION">LPRng</b> <var class="LITERAL">Z</var> 198 options use the <var class= 199 "LITERAL">:prefix_option_to_option=from,from... to</var> 200 facility to prefix the <span class="emphasis"><i class= 201 "EMPHASIS">from</i></span> control file lines to the <span 202 class="emphasis"><i class="EMPHASIS">to</i></span> control 203 file line. For example:</p> 204 205 <div class="INFORMALEXAMPLE"> 206 <a name="AEN3839"></a> 207<pre class="SCREEN"> 208 # System V to LPRng - S and O to Z options 209 convert:server:tc=.common 210 :lp=raw@server:prefix_option_to_option=S,O Z 211 # LPRng to System V O options 212 convert:server:tc=.common 213 :lp=raw@server:prefix_option_to_option=Z O 214</pre> 215 </div> 216 <br> 217 <br> 218 </div> 219 220 <div class="SECT2"> 221 <h2 class="SECT2"><a name="AEN3841">4.19.3. Selecting a 222 Single Option - Muliple Queues</a></h2> 223 224 <p>Here is an example of how you can set up queues that 225 will append the appropriate <var class="LITERAL">Z</var> 226 option to select landscape mode, do duplex printing, or 227 select legal or ledger size paper:</p> 228 229 <div class="INFORMALEXAMPLE"> 230 <a name="AEN3845"></a> 231<pre class="SCREEN"> 232 landscape:lp=%P@server 233 landscape:server:tc=.common 234 :lp=raw@server:append_z=landscape 235 duplex:lp=%P@server 236 duplex:server:tc=.common 237 :lp=raw@server:append_z=duplex 238 ledger:lp=%P@server 239 ledger:server:tc=.common 240 :lp=raw@server:append_z=ledger 241 legal:lp=%P@server 242 legal:server:tc=.common 243 :lp=raw@server:append_z=legal 244 raw:server:tc=.common:lp=.... 245 :filter=/usr/local/libexec/filters/ifhp 246 .common:sd=/var/spool/lpd/%P 247</pre> 248 </div> 249 <br> 250 <br> 251 252 <p>The problem with this method is that for each option we 253 need to define a queue whose only purpose is to append the 254 appropriate option and then forward this to the main print 255 queue.</p> 256 </div> 257 258 <div class="SECT2"> 259 <h2 class="SECT2"><a name="INCOMINGCONTROLFILTER">4.19.4. 260 Selecting Multiple Options - Single Queue</a></h2> 261 262 <p>In the previous section, we showed how to set up a queue 263 that would append a single option to the control file <var 264 class="LITERAL">Z</var> line. If we want to have 265 combinations of option options specified by the printer 266 name then we will have to create a large number of queues 267 each with a different set of options and each appending a 268 different set of values. The problem becomes compounded 269 when we have many printers, each of which requires these 270 options.</p> 271 272 <p>The solution to this problem originated with the <b 273 class="APPLICATION">apsfilter</b> program written by 274 Andreas Klemm and Thomas Bueschgens. They made the 275 observeration that if we know the name of the print queue 276 then we can use this name to select options for the 277 printer. The <b class="APPLICATION">LPRng</b> provides this 278 functionality by using wildcard queues and <span class= 279 "emphasis"><i class="EMPHASIS">editing</i></span> or <span 280 class="emphasis"><i class="EMPHASIS">filtering</i></span> 281 the control file when the job is submitted to the spool 282 queue.</p> 283 284 <p>The <var class= 285 "LITERAL">incoming_control_filter=/path</var> option 286 specifies a filter that processes the incoming job control 287 file. It should be used to update and/or modify information 288 on the option lines of the control files of incoming jobs. 289 It reads the control file on its <acronym class= 290 "ACRONYM">STDIN</acronym>, writes the new control file on 291 its <acronym class="ACRONYM">STDOUT</acronym>, and then 292 exits. A 0 exit code value causes normal processing of the 293 job, <var class="LITERAL">JHOLD</var> will hold the job, 294 and any other value will cause the job to be discarded.</p> 295 296 <p>The following shows how we can set up a single queue 297 that will allow various combinations of options to be 298 selected by the format of the queue name:</p> 299 300 <div class="INFORMALEXAMPLE"> 301 <a name="AEN3863"></a> 302<pre class="SCREEN"> 303 # for clients 304 pr|pr_*:lp=%Q@server 305 # for server 306 pr|pr_*:server 307 :tc=.common:lp=.... 308 :incoming_control_filter=/usr/local/libexec/filters/update_z 309 :filter=/usr/local/libexec/filters/ifhp 310 .common:sd=/var/spool/lpd/%P 311</pre> 312 </div> 313 <br> 314 <br> 315 316 <p>The <var class="LITERAL">pr</var> and <var class= 317 "LITERAL">pr_*</var> aliases will match printer <var class= 318 "LITERAL">pr</var> all print queue names starting with <var 319 class="LITERAL">pr_</var>. We can then use various suffixes 320 to select job options. The following filter program uses 321 the <var class="LITERAL">_landscape</var>, <var class= 322 "LITERAL">_legal</var>, and <var class= 323 "LITERAL">_ledger</var> suffixes to set the corresponding 324 option in the <var class="LITERAL">Z</var> file. This 325 program and other are available in the <b class= 326 "APPLICATION">LPRng</b> distribution in the <tt class= 327 "FILENAME">UTILS</tt> directory. You should note that 328 additional options can be specified as desired.</p> 329 330 <div class="INFORMALEXAMPLE"> 331 <a name="AEN3876"></a> 332<pre class="SCREEN"> 333 # 334 #!/usr/bin/perl 335 # update_z script: 336 # Determine the options according to the format of the queue name 337 # Inspired by the psfilter code of Andreas Klemm 338 # and Thomas Bueschgens 339 # First, get command line arguments 340 # 341 use Getopt::Std; 342 my(%args,$Q,$Zopts,@file); 343 getopts( 344 "A:B:C:D:E:F:G:H:I:J:K:L:M:N:O:P:Q:R:S:T:U:V:W:X:Y:Z:" . 345 "a:b:cd:e:f:g:h:i:j:k:l:m:n:o:p:q:r:s:t:u:v:w:x:y:z:", 346 \%args ); 347 # read stdin 348 @file = <STDIN>; 349 $Zopts = ""; 350 # first use command line Queue name 351 $Q = $args{"Q"}; 352 if( not $Q and (($Q) = grep(/^Q/,@file)) ){ 353 # next use control file Queue name 354 chomp $Q if $Q; 355 } 356 # now we split up the name and use as parameters for Z options 357 while( $Q =~ /_([^_]+)/g ){ 358 # you can add them or test and then add them 359 if( $1 eq "landscape" 360 or $1 eq "legal" 361 or $1 eq "ledger" ){ 362 $Zopts .= ",$1" 363 } 364 } 365 if( $Zopts ){ 366 # remove leading comma 367 $Zopts = substr( $Zopts, 1 ); 368 #replace or prefix Z options 369 if( not (grep { s/$/,$Zopts/ if /^Z/; } @file) ){ 370 print "Z" . $Zopts . "\n"; 371 } 372 } 373 print @file if( @file ); 374 exit 0 375 376 Example Input Control file: 377 378 ... 379 Zover 380 Qlp_landscape_ledger 381 ... 382 383 Modified output: 384 385 ... 386 Zover,landscape,ledger 387 Qlp_landscape_ledger 388 ... 389</pre> 390 </div> 391 <br> 392 <br> 393 394 <p>The Perl script first uses the <code class= 395 "FUNCTION">getopts</code> function to parse the command 396 line options. If there is not a command line <var class= 397 "LITERAL">-Q</var> option then the control file <var class= 398 "LITERAL">Q</var> line is used after stripping the trailing 399 newline. The queue name is then split up into parts 400 separated by underscores (<var class="LITERAL">_</var>) and 401 those used as option names. As shown in the example, the 402 literal values are placed in the control file. You can also 403 use the following code segment to translate short forms of 404 options into longer ones:</p> 405 406 <div class="INFORMALEXAMPLE"> 407 <a name="AEN3883"></a> 408<pre class="SCREEN"> 409 while( $Q =~ /_([^_]+)/g ){ 410 # you can add them or test and then add them 411 Zopts .= ",landscape" if( $1 eq "ld" ); 412 Zopts .= ",ledger" if( $1 eq "11" ); 413 Zopts .= ",legal" if( $1 eq "15" ); 414 Zopts .= ",a4" if( $1 eq "a4" ); 415 } 416</pre> 417 </div> 418 <br> 419 <br> 420 </div> 421 </div> 422 423 <div class="NAVFOOTER"> 424 <hr align="LEFT" width="100%"> 425 426 <table summary="Footer navigation table" width="100%" border= 427 "0" cellpadding="0" cellspacing="0"> 428 <tr> 429 <td width="33%" align="left" valign="top"><a href= 430 "x3694.htm" accesskey="P">Prev</a></td> 431 432 <td width="34%" align="center" valign="top"><a href= 433 "index.htm" accesskey="H">Home</a></td> 434 435 <td width="33%" align="right" valign="top"><a href= 436 "x3885.htm" accesskey="N">Next</a></td> 437 </tr> 438 439 <tr> 440 <td width="33%" align="left" valign="top">Routing Jobs To 441 Print Queues</td> 442 443 <td width="34%" align="center" valign="top"><a href= 444 "tutorial.htm" accesskey="U">Up</a></td> 445 446 <td width="33%" align="right" valign="top">Interfacing to 447 Non-LPRng Spoolers</td> 448 </tr> 449 </table> 450 </div> 451 </body> 452</html> 453 454