summarylogtreecommitdiffstats
path: root/doc_debianwiki.html
blob: 9ad5fb2d14337a232e7e73cca8b71cadf91375e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" href="/htdocs/favicon.ico">
<script type="text/javascript" src="/htdocs/bugstatus.js"></script>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<meta name="robots" content="index,nofollow">

<title>Tea4CUPS - Debian Wiki</title>
<script type="text/javascript" src="/htdocs/common/js/common.js"></script>

<script type="text/javascript">
<!--
var search_hint = "Search";
//-->
</script>


<link rel="stylesheet" type="text/css" charset="utf-8" media="all" href="/htdocs/debwiki/css/common.css">
<link rel="stylesheet" type="text/css" charset="utf-8" media="screen" href="/htdocs/debwiki/css/screen.css">
<link rel="stylesheet" type="text/css" charset="utf-8" media="print" href="/htdocs/debwiki/css/print.css">
<link rel="stylesheet" type="text/css" charset="utf-8" media="projection" href="/htdocs/debwiki/css/projection.css">
<link rel="stylesheet" type="text/css" charset="utf-8" media="all" href="/htdocs/debian-wiki-1.0.css">

<!-- css only for MS IE6/IE7 browsers -->
<!--[if lt IE 8]>
   <link rel="stylesheet" type="text/css" charset="utf-8" media="all" href="/htdocs/debwiki/css/msie.css">
<![endif]-->


<link rel="alternate" title="Debian Wiki: Tea4CUPS" href="/Tea4CUPS?diffs=1&amp;show_att=1&amp;action=rss_rc&amp;unique=0&amp;page=Tea4CUPS&amp;ddiffs=1" type="application/rss+xml">


<link rel="Start" href="/FrontPage">
<link rel="Alternate" title="Wiki Markup" href="/Tea4CUPS?action=raw">
<link rel="Alternate" media="print" title="Print View" href="/Tea4CUPS?action=print">
<link rel="Search" href="/FindPage">
<link rel="Index" href="/TitleIndex">
<link rel="Glossary" href="/WordIndex">
<link rel="Help" href="/HelpOnFormatting">
</head>

<body  lang="en" dir="ltr">
<div id="logo"><a href="https://www.debian.org" title="Debian Homepage"><img src="https://www.debian.org/Pics/openlogo-50.png" alt="Debian" width="50" height="61"></a></div>
<div id="header">
<div id="wikisection">
<p class="section"><a href="/FrontPage" title="Debian Wiki Homepage">Wiki</a></p>
<div id="username"><a href="/Tea4CUPS?action=login" id="login" rel="nofollow">Login</a></div>
</div>
<div id="navbar">

<ul id="navibar">
<li class="wikilink"><a href="/FrontPage">FrontPage</a></li><li class="wikilink"><a href="/RecentChanges">RecentChanges</a></li><li class="wikilink"><a href="/FindPage">FindPage</a></li><li class="wikilink"><a href="/HelpContents">HelpContents</a></li><li class="current"><a href="/Tea4CUPS">Tea4CUPS</a></li>
</ul>

</div>

<form id="searchform" method="get" action="/Tea4CUPS">
<div>
<input type="hidden" name="action" value="fullsearch">
<input type="hidden" name="context" value="180">
<label for="searchinput">Search:</label>
<input id="searchinput" type="text" name="value" value="" size="20"
    onfocus="searchFocus(this)" onblur="searchBlur(this)"
    onkeyup="searchChange(this)" onchange="searchChange(this)" alt="Search">
<input id="titlesearch" name="titlesearch" type="submit"
    value="Titles" alt="Search Titles">
<input id="fullsearch" name="fullsearch" type="submit"
    value="Text" alt="Search Full Text">
</div>
</form>
<script type="text/javascript">
<!--// Initialize search form
var f = document.getElementById('searchform');
f.getElementsByTagName('label')[0].style.display = 'none';
var e = document.getElementById('searchinput');
searchChange(e);
searchBlur(e);
//-->
</script>

<div id="logo"><a href="https://www.debian.org" title="Debian Homepage"><img src="https://www.debian.org/Pics/openlogo-50.png" alt="Debian" width="50" height="61"></a></div>

<div id="breadcrumbs"><a href="/FrontPage" title="Debian Wiki Homepage">Wiki</a><span class="sep">/</span>

</div>

<ul class="editbar"><li><a href="/Tea4CUPS?action=login" id="login-1" rel="nofollow">Login</a></li><li class="toggleCommentsButton" style="display:none;"><a href="#" class="nbcomment" onClick="toggleComments();return false;">Comments</a></li><li><a class="nbinfo" href="/Tea4CUPS?action=info" rel="nofollow">Info</a></li><li><a class="nbattachments" href="/Tea4CUPS?action=AttachFile" rel="nofollow">Attachments</a></li><li>
<form class="actionsmenu" method="GET" action="/Tea4CUPS">
<div>
    <label>More Actions:</label>
    <select name="action"
        onchange="if ((this.selectedIndex != 0) &&
                      (this.options[this.selectedIndex].disabled == false)) {
                this.form.submit();
            }
            this.selectedIndex = 0;">
        <option value="raw">Raw Text</option>
<option value="print">Print View</option>
<option value="RenderAsDocbook">Render as Docbook</option>
<option value="refresh">Delete Cache</option>
<option value="show" disabled class="disabled">------------------------</option>
<option value="SpellCheck">Check Spelling</option>
<option value="LikePages">Like Pages</option>
<option value="LocalSiteMap">Local Site Map</option>
<option value="show" disabled class="disabled">------------------------</option>
<option value="RenamePage" disabled class="disabled">Rename Page</option>
<option value="DeletePage" disabled class="disabled">Delete Page</option>
<option value="show" disabled class="disabled">------------------------</option>
<option value="show" disabled class="disabled">Subscribe User</option>
<option value="show" disabled class="disabled">------------------------</option>
<option value="show" disabled class="disabled">Remove Spam</option>
<option value="show" disabled class="disabled">Revert to this revision</option>
<option value="PackagePages">Package Pages</option>
<option value="show" disabled class="disabled">------------------------</option>
<option value="Load">Load</option>
<option value="Save">Save</option>
<option value="SlideShow">SlideShow</option>
    </select>
    <input type="submit" value="Do">
    
</div>
<script type="text/javascript">
<!--// Init menu
actionsMenuInit('More Actions:');
//-->
</script>
</form>
</li></ul>

<h1 id="locationline">


<ul id="pagelocation">
<li><a href="/Tea4CUPS">Tea4CUPS</a></li>
</ul>

</h1>
</div>

<div id="page" lang="en" dir="ltr">
<div dir="ltr" id="content" lang="en"><span class="anchor" id="top"></span>
<span class="anchor" id="line-1"></span><span class="anchor" id="line-2"></span><span class="anchor" id="line-3"></span><p class="line867"><small><a href="/DebianWiki/EditorGuide#translation">Translation(s)</a>: none</small> <span class="anchor" id="line-4"></span><hr /><p class="line874"> <span class="anchor" id="line-5"></span>A description of the capabilities of Tea4CUPS with examples. <span class="anchor" id="line-6"></span><span class="anchor" id="line-7"></span><p class="line867"><span class="anchor" id="line-8"></span><p class="line867"><div class="table-of-contents"><p class="table-of-contents-heading">Contents<ol><li>
<a href="#Introduction_to_Tea4CUPS">Introduction to Tea4CUPS</a></li><li>
<a href="#Wrapping_a_Backend_with_Tea4CUPS">Wrapping a Backend with Tea4CUPS</a></li><li>
<a href="#Capturing_an_Input_File">Capturing an Input File</a></li><li>
<a href="#Enforcing_number-up.3D2_Printing_.281.29">Enforcing number-up=2 Printing (1)</a></li><li>
<a href="#Enforcing_number-up.3D2_Printing_.282.29">Enforcing number-up=2 Printing (2)</a></li><li>
<a href="#Manual_Duplexing_.281.29">Manual Duplexing (1)</a></li><li>
<a href="#Manual_Duplexing_.282.29">Manual Duplexing (2)</a></li><li>
<a href="#Manual_Duplexing_.283.29">Manual Duplexing (3)</a></li><li>
<a href="#Printing_Microsoft_Documents">Printing Microsoft Documents</a></li><li>
<a href="#Text_to_PDF_with_a_Selected_Font">Text to PDF with a Selected Font</a></li><li>
<a href="#Creating_Searchable_PDFs_from_Text_Files_.281.29">Creating Searchable PDFs from Text Files (1)</a></li><li>
<a href="#Creating_Searchable_PDFs_from_Text_Files_.282.29">Creating Searchable PDFs from Text Files (2)</a></li><li>
<a href="#Virtual_PDF_Printer_.281.29">Virtual PDF Printer (1)</a></li><li>
<a href="#Virtual_PDF_Printer_.282.29">Virtual PDF Printer (2)</a></li><li>
<a href="#Creating_a_PDF.2FA_Document_with_unoconv">Creating a PDF/A Document with unoconv</a></li><li>
<a href="#Creating_a_PDF.2FA_Document_with_Ghostscript">Creating a PDF/A Document with Ghostscript</a></li><li>
<a href="#Printer_Accounting">Printer Accounting</a></li><li>
<a href="#Printer_Accounting_and_the_Page_Log">Printer Accounting and the Page Log</a></li><li>
<a href="#Resharing_a_Raw_Print_Queue">Resharing a Raw Print Queue</a></li><li>
<a href="#A_Customised_Printing_Dialog">A Customised Printing Dialog</a></li><li>
<a href="#Dealing_with_Duplicate_Print_Jobs">Dealing with Duplicate Print Jobs</a></li><li>
<a href="#Credits">Credits</a></li><li>
<a href="#See_Also">See Also</a></li><li>
<a href="#Finally">Finally</a></li></ol></li></ol></li></ol></div> <span class="anchor" id="line-9"></span><span class="anchor" id="line-10"></span><p class="line867"><span class="anchor" id="intro"></span> <span class="anchor" id="line-11"></span>
<h3 id="Introduction_to_Tea4CUPS">Introduction to Tea4CUPS</h3>
<span class="anchor" id="line-12"></span><span class="anchor" id="line-13"></span><p class="line862">The final filter a print job passes through before being sent to a printer is the <a class="interwiki" href="https://manpages.debian.org/man/backend" title="DebianMan">backend</a> filter (usb, parallel, socket etc), which transports the printer-ready job to the printer. <a class="interwiki" href="https://packages.debian.org/cups-tea4cups" title="DebianPkg">Tea4CUPS</a> is not intended to replace the function of any existing backend being used with the printer. It is a script (written in <a class="interwiki" href="https://packages.debian.org/python" title="DebianPkg">Python</a>) which wraps round the chosen backend to manipulate print data before or after they are dispatched by the backend to the printer. <span class="anchor" id="line-14"></span><span class="anchor" id="line-15"></span><p class="line867"><span class="anchor" id="line-16"></span><span class="anchor" id="line-17"></span><span class="anchor" id="line-18"></span><span class="anchor" id="line-19"></span><span class="anchor" id="line-20"></span><span class="anchor" id="line-21"></span><span class="anchor" id="line-22"></span><span class="anchor" id="line-23"></span><span class="anchor" id="line-24"></span><span class="anchor" id="line-25"></span><span class="anchor" id="line-26"></span><pre><span class="anchor" id="line-1"></span>                          DATA1=DATA2 without a Tea4CUPS filter.
<span class="anchor" id="line-2"></span>
<span class="anchor" id="line-3"></span>+------------+    +--------------+       +----------+       +----------+       +---------+
<span class="anchor" id="line-4"></span>|            |    |     CUPS     | DATA1 | Tea4CUPS | DATA2 | Tea4CUPS | DATA3 |         |
<span class="anchor" id="line-5"></span>| Input file |---&gt;|      +       |------&gt;|  filter  |------&gt;| wrapped  |------&gt;| Printer |
<span class="anchor" id="line-6"></span>|            |    | cups-filters |       |          |   |   | backend  |   |   |         |
<span class="anchor" id="line-7"></span>+____________+    +--------------+       +----------+   |   +----------+   |   +---------+
<span class="anchor" id="line-8"></span>                                                        |                  |
<span class="anchor" id="line-9"></span>                                                        |                  |
<span class="anchor" id="line-10"></span>                                           Prehooks &lt;---+                  +---&gt; Posthooks</pre><span class="anchor" id="line-27"></span><span class="anchor" id="line-28"></span><p class="line862">The manipulation may be done via a combination of prehooks, posthooks and a filter. There can be only one filter per print queue but as many hooks as wanted can be specified for the same <a href="/PrintQueuesCUPS#printqueue">print queue</a>. Hooks may be scripts and do not alter the data which are sent to the printer. If the data should be modified before being sent to a hook or the printer a filter should be defined. <span class="anchor" id="line-29"></span><span class="anchor" id="line-30"></span><ul><li>Hooks manipulate a data stream without modifying the original stream. <span class="anchor" id="line-31"></span></li><li>The data stream going to the printer (DATA3) comes from CUPS+cups-filters (DATA1) or the Tea4CUPS filter (DATA2), if there is one. <span class="anchor" id="line-32"></span><span class="anchor" id="line-33"></span></li></ul><p class="line874">There is very adequate documentation (including examples) for Tea4CUPS <span class="anchor" id="line-34"></span>in <em>/etc/cups/tea4cups.conf</em> and the README in <em>/usr/share/doc/cups-tea4cups/</em>. <span class="anchor" id="line-35"></span><span class="anchor" id="line-36"></span><ul><li>The contents of a hook directive and a filter are run as the root user. <span class="anchor" id="line-37"></span></li><li>The documentation has a list of useful environment variables which can be made available to the commands executed by a hook. The defined hook does all the required work to reformat the job and send it (and any options) to a second queue and/or another destination. <span class="anchor" id="line-38"></span></li><li>There can be multiple hooks, so the same job can be processed in different ways and sent to different print queues and destinations. <span class="anchor" id="line-39"></span></li><li>Scripts run by hooks need not connect with another print queue.  <span class="anchor" id="line-40"></span><span class="anchor" id="line-41"></span></li></ul><p class="line867"><span class="anchor" id="wrapping"></span> <span class="anchor" id="line-42"></span>
<h3 id="Wrapping_a_Backend_with_Tea4CUPS">Wrapping a Backend with Tea4CUPS</h3>
<span class="anchor" id="line-43"></span><span class="anchor" id="line-44"></span><p class="line862">A print queue managed by Tea4CUPS can be created with <a href="/PrintQueuesCUPS#webinterface">lpadmin</a>, the <a href="/PrintQueuesCUPS#lpadmin">web interface</a> or <a href="/PrintQueuesCUPS#scp">system-config-printer</a>. If the unwrapped <a href="/PrintQueuesCUPS#deviceuri">DEVICE_URI</a> is socket://192.168.7.200:9100 the wrapped one (the -v option to lpadmin) would be <span class="anchor" id="line-45"></span><span class="anchor" id="line-46"></span><p class="line867"><span class="anchor" id="line-47"></span><span class="anchor" id="line-48"></span><span class="anchor" id="line-49"></span><span class="anchor" id="line-50"></span><pre><span class="anchor" id="line-1-1"></span>tea4cups:/socket://192.168.7.200:9100
<span class="anchor" id="line-2-1"></span>or
<span class="anchor" id="line-3-1"></span>tea4cups:socket://192.168.7.200:9100</pre><span class="anchor" id="line-51"></span><span class="anchor" id="line-52"></span><p class="line874">On Jessie lpadmin complains about tea4cups://socket://192.168.7.200:9100. <span class="anchor" id="line-53"></span><span class="anchor" id="line-54"></span><p class="line867"><span class="anchor" id="capturing"></span> <span class="anchor" id="line-55"></span>
<h3 id="Capturing_an_Input_File">Capturing an Input File</h3>
<span class="anchor" id="line-56"></span><span class="anchor" id="line-57"></span><p class="line867"><em>tea4cups://</em> is a special device-uri in that it is virtual. It is useful when <span class="anchor" id="line-58"></span>sending data to a real printer and a <a href="/Tea4CUPS#wrapping">wrapped backend</a> is not wanted. The input is still available to be manipulated by hooks and/or a filter. <span class="anchor" id="line-59"></span><span class="anchor" id="line-60"></span><p class="line862">It is tempting to think <em>tea4cups:/<img alt="file:/" class="external_image" src="file:/" title="file:/" />tmp/out</em> would print to <em>/tmp/out</em>. However, <em><img alt="file:/" class="external_image" src="file:/" title="file:/" /></em> is built into CUPS and is not a backend device-uri. But, with a virtual device-uri, a hook could be used for capturing the input file. The following technique is used in some of the scripts on this page. <span class="anchor" id="line-61"></span><span class="anchor" id="line-62"></span><p class="line874">Set up a virtual raw queue: <span class="anchor" id="line-63"></span><span class="anchor" id="line-64"></span><p class="line867"><span class="anchor" id="line-65"></span><span class="anchor" id="line-66"></span><pre><span class="anchor" id="line-1-2"></span>   lpadmin -p virtq -v tea4cups:// -E -m raw</pre><span class="anchor" id="line-67"></span><span class="anchor" id="line-68"></span><p class="line874">The input file avoids any filtering which would be done by cups-filters and instead is sent directly to the tea4cups wrapped backend: <span class="anchor" id="line-69"></span><span class="anchor" id="line-70"></span><p class="line867"><span class="anchor" id="line-71"></span><span class="anchor" id="line-72"></span><span class="anchor" id="line-73"></span><span class="anchor" id="line-74"></span><span class="anchor" id="line-75"></span><span class="anchor" id="line-76"></span><span class="anchor" id="line-77"></span><span class="anchor" id="line-78"></span><span class="anchor" id="line-79"></span><span class="anchor" id="line-80"></span><span class="anchor" id="line-81"></span><pre><span class="anchor" id="line-1-3"></span>                        DATA1=DATA2 without a Tea4CUPS filter.
<span class="anchor" id="line-2-2"></span>
<span class="anchor" id="line-3-2"></span>+------------+         +----------+       +------------------+          +---------+
<span class="anchor" id="line-4-1"></span>|            |  DATA1  | Tea4CUPS | DATA2 | Tea4CUPS wrapped |   DATA3  |         |
<span class="anchor" id="line-5-1"></span>| Input file |--------&gt;|  filter  |------&gt;| virtual backend  |---------&gt;| Nowhere |
<span class="anchor" id="line-6-1"></span>|            |         |          |   |   |                  |    |     |         |
<span class="anchor" id="line-7-1"></span>+____________+         +----------+   |   +------------------+    |     +---------+
<span class="anchor" id="line-8-1"></span>                                      |                           |
<span class="anchor" id="line-9-1"></span>                                      |                           |
<span class="anchor" id="line-10-1"></span>                         Prehooks &lt;---+                           +---&gt; Posthooks</pre><span class="anchor" id="line-82"></span><span class="anchor" id="line-83"></span><p class="line874">A hook or filter can now work directly with the input file to modify it and send the result to a print queue which has been set up with: <span class="anchor" id="line-84"></span><span class="anchor" id="line-85"></span><p class="line867"><span class="anchor" id="line-86"></span><span class="anchor" id="line-87"></span><pre><span class="anchor" id="line-1-4"></span>  lpadmin -p realq -v &lt;DEVICE_URI&gt; -E -m &lt;PPD&gt;</pre><span class="anchor" id="line-88"></span><span class="anchor" id="line-89"></span><p class="line874">Jobs received from virtq can be sent to realq using a prehook or posthook with the line <span class="anchor" id="line-90"></span><span class="anchor" id="line-91"></span><p class="line867"><span class="anchor" id="line-92"></span><span class="anchor" id="line-93"></span><pre><span class="anchor" id="line-1-5"></span>  lp -d realq &lt;OPTIONS&gt; &lt;file&gt;</pre><span class="anchor" id="line-94"></span><span class="anchor" id="line-95"></span><p class="line874">in it. <span class="anchor" id="line-96"></span><span class="anchor" id="line-97"></span><ul><li>Depending on the use case, the queue virtq could be the one advertised to users. The queue realq would not be published and would only be visible on the server. This way any processing of the input file would be completely invisible to a user. <span class="anchor" id="line-98"></span><span class="anchor" id="line-99"></span></li></ul><p class="line867"><span class="anchor" id="nup1"></span> <span class="anchor" id="line-100"></span>
<h3 id="Enforcing_number-up.3D2_Printing_.281.29">Enforcing number-up=2 Printing (1)</h3>
<span class="anchor" id="line-101"></span><span class="anchor" id="line-102"></span><p class="line874">A question which is sometimes seen concerns wanting to enforce default <span class="anchor" id="line-103"></span>printer settings for applications and printing from the command line. It <span class="anchor" id="line-104"></span>might be because some users on a network don't have the patience to check their printer settings or maybe it is seen as desirable to limit the alteration of some settings on an expensive-to-run colour printer. Within CUPS there is no surefire way of achieving this; a user is either allowed to print or not print. If allowed to print then that user can change the print job options in the application's interface or with <a class="interwiki" href="https://manpages.debian.org/man/lpoptions" title="DebianMan">lpoptions</a>. This is irrespective of how the print queue <a class="interwiki" href="https://manpages.debian.org/man/lpadmin" title="DebianMan">has been set up</a>. <span class="anchor" id="line-105"></span><span class="anchor" id="line-106"></span><p class="line862">Set up a <a href="/Tea4CUPS#capturing">virtual raw queue</a>. A prehook such as <span class="anchor" id="line-107"></span><span class="anchor" id="line-108"></span><p class="line867"><span class="anchor" id="line-109"></span><span class="anchor" id="line-110"></span><pre><span class="anchor" id="line-1-6"></span>  prehook_something : lp -d realq -o &quot;$TEAOPTIONS&quot; &quot;$TEADATAFILE&quot;</pre><span class="anchor" id="line-111"></span><span class="anchor" id="line-112"></span><p class="line874">would pass the options given to virtq on to realq unchanged. <span class="anchor" id="line-113"></span><span class="anchor" id="line-114"></span><p class="line874">With <span class="anchor" id="line-115"></span><span class="anchor" id="line-116"></span><p class="line867"><span class="anchor" id="line-117"></span><span class="anchor" id="line-118"></span><pre><span class="anchor" id="line-1-7"></span>  prehook_enforce : lp -d realq -o &quot;$TEAOPTIONS number-up=2&quot; &quot;$TEADATAFILE&quot;</pre><span class="anchor" id="line-119"></span><span class="anchor" id="line-120"></span><p class="line862">the <em>number-up=2</em> option replaces any similar option in $TEAOPTIONS. <span class="anchor" id="line-121"></span><span class="anchor" id="line-122"></span><p class="line862">An option to print double-sided <a href="/Tea4CUPS#nup2">might not be present</a> in the virtq options list but it could be wanted as a default for printing to realq. <em>sides=two-sided-long-edge</em> looks like something which could be put in <em>prehook_enforce</em> to make every print job use a duplex facility on the printer. <span class="anchor" id="line-123"></span><span class="anchor" id="line-124"></span><p class="line867"><span class="anchor" id="nup2"></span> <span class="anchor" id="line-125"></span>
<h3 id="Enforcing_number-up.3D2_Printing_.282.29">Enforcing number-up=2 Printing (2)</h3>
<span class="anchor" id="line-126"></span><span class="anchor" id="line-127"></span><p class="line874">Because it is a raw queue the options offered by virtq in the printing <span class="anchor" id="line-128"></span>dialogue for an application such as Firefox and with <tt class="backtick">lpoptions</tt> are limited. They are certainly fewer than the options which realq with its PPD would display. This might not matter too much to most users if realq has been set up sensibly, but, nevertheless, not revealing the full potential of realq could be regarded as a deficiency by users and administrators alike. <span class="anchor" id="line-129"></span><span class="anchor" id="line-130"></span><p class="line862">Instead of a setting up a virtual raw queue <a href="/Tea4CUPS#nup1">as before</a> set up pretendq with the PPD used for realq: <span class="anchor" id="line-131"></span><span class="anchor" id="line-132"></span><p class="line867"><span class="anchor" id="line-133"></span><span class="anchor" id="line-134"></span><pre><span class="anchor" id="line-1-8"></span>lpadmin -p pretendq -v tea4cups:/socket://192.168.7.200:9100 -E -m &lt;PPD_for_realq&gt;</pre><span class="anchor" id="line-135"></span><span class="anchor" id="line-136"></span><p class="line874">We do not want the cups-filters processed data sent to the printer or used by a prehook. With the prehook line <span class="anchor" id="line-137"></span><span class="anchor" id="line-138"></span><p class="line867"><span class="anchor" id="line-139"></span><span class="anchor" id="line-140"></span><pre><span class="anchor" id="line-1-9"></span>prehook_spool : /usr/local/bin/spool</pre><span class="anchor" id="line-141"></span><span class="anchor" id="line-142"></span><p class="line874">this script would realise these two objectives: <span class="anchor" id="line-143"></span><span class="anchor" id="line-144"></span><p class="line867"><span class="anchor" id="line-145"></span><span class="anchor" id="line-146"></span><span class="anchor" id="line-147"></span><span class="anchor" id="line-148"></span><span class="anchor" id="line-149"></span><span class="anchor" id="line-150"></span><span class="anchor" id="line-151"></span><span class="anchor" id="line-152"></span><span class="anchor" id="line-153"></span><span class="anchor" id="line-154"></span><span class="anchor" id="line-155"></span><span class="anchor" id="line-156"></span><span class="anchor" id="line-157"></span><span class="anchor" id="line-158"></span><span class="anchor" id="line-159"></span><span class="anchor" id="line-160"></span><pre><span class="anchor" id="line-1-10"></span>#!/bin/bash
<span class="anchor" id="line-2-3"></span>  
<span class="anchor" id="line-3-3"></span># spool: a script to print a file from /var/spool/cups.
<span class="anchor" id="line-4-2"></span>
<span class="anchor" id="line-5-2"></span># Location of CUPS' &quot;d&quot; files.
<span class="anchor" id="line-6-2"></span>DDIR=/var/spool/cups
<span class="anchor" id="line-7-2"></span># Find job originally sent to the queue.
<span class="anchor" id="line-8-2"></span>JOB=$(ls $DDIR | grep &quot;$TEAJOBID&quot;-001)
<span class="anchor" id="line-9-2"></span>
<span class="anchor" id="line-10-2"></span>lp -d realq -o &quot;$TEAOPTIONS number-up=2&quot;  $DDIR/$JOB
<span class="anchor" id="line-11"></span>
<span class="anchor" id="line-12"></span># Causes the job not to be sent to the real backend. Not needed
<span class="anchor" id="line-13"></span># if the URI for pretendq is tea4cups:/file:/dev/null.
<span class="anchor" id="line-14"></span>exit -1</pre><span class="anchor" id="line-161"></span><span class="anchor" id="line-162"></span><p class="line867"><span class="anchor" id="manualdup-1"></span> <span class="anchor" id="line-163"></span>
<h3 id="Manual_Duplexing_.281.29">Manual Duplexing (1)</h3>
<span class="anchor" id="line-164"></span><span class="anchor" id="line-165"></span><p class="line874">Without duplexing cabability on the printer double-sided printing requires manual intervention. One way is to print the odd numbered pages of a document in reverse and then print the even numbered pages in normal order after returning the first print run to the printer tray with the first printed page at the bottom of the pile. Let's see the result of that with three documents having, respectively, three, four and five pages. <span class="anchor" id="line-166"></span><span class="anchor" id="line-167"></span><p class="line867"><span class="anchor" id="line-168"></span><span class="anchor" id="line-169"></span><pre><span class="anchor" id="line-1-11"></span>lp -d &lt;print_queue&gt; docA docB docC</pre><span class="anchor" id="line-170"></span><span class="anchor" id="line-171"></span><p class="line874">The order of printing is <span class="anchor" id="line-172"></span><span class="anchor" id="line-173"></span><p class="line867"><span class="anchor" id="line-174"></span><span class="anchor" id="line-175"></span><pre><span class="anchor" id="line-1-12"></span>C5 C3 C1 B3 B1 A3 A1</pre><span class="anchor" id="line-176"></span><span class="anchor" id="line-177"></span><p class="line874">and the order from the top of the pile is <span class="anchor" id="line-178"></span><span class="anchor" id="line-179"></span><p class="line867"><span class="anchor" id="line-180"></span><span class="anchor" id="line-181"></span><pre><span class="anchor" id="line-1-13"></span>A1 A3 B1 B3 C1 C3 C5</pre><span class="anchor" id="line-182"></span><span class="anchor" id="line-183"></span><p class="line874">Printing the even numbered pages gives <span class="anchor" id="line-184"></span><span class="anchor" id="line-185"></span><p class="line867"><span class="anchor" id="line-186"></span><span class="anchor" id="line-187"></span><pre><span class="anchor" id="line-1-14"></span>A2 B2 B4 C2 C4</pre><span class="anchor" id="line-188"></span><span class="anchor" id="line-189"></span><p class="line874">so, matching up sheets, we have <span class="anchor" id="line-190"></span><span class="anchor" id="line-191"></span><p class="line867"><span class="anchor" id="line-192"></span><span class="anchor" id="line-193"></span><span class="anchor" id="line-194"></span><pre><span class="anchor" id="line-1-15"></span>A1 A3 B1 B3 C1 C3 C6
<span class="anchor" id="line-2-4"></span>A2 B2 B4 C2 C4</pre><span class="anchor" id="line-195"></span><span class="anchor" id="line-196"></span><p class="line874">There are two consequences here: <span class="anchor" id="line-197"></span><span class="anchor" id="line-198"></span><p class="line867"><span class="anchor" id="line-199"></span><span class="anchor" id="line-200"></span><span class="anchor" id="line-201"></span><pre><span class="anchor" id="line-1-16"></span>Two sheets have pages from different documents: A3, B2 and B3, C2.
<span class="anchor" id="line-2-5"></span>The last two pages in the pile are not pulled out of the tray.</pre><span class="anchor" id="line-202"></span><span class="anchor" id="line-203"></span><p class="line874">What we want is for a blank page to be added to the end of even numbered pages of a document if the total number of pages in that document is odd. Like this (using 0 for an empty page): <span class="anchor" id="line-204"></span><span class="anchor" id="line-205"></span><p class="line867"><span class="anchor" id="line-206"></span><span class="anchor" id="line-207"></span><pre><span class="anchor" id="line-1-17"></span>A2 A0 B2 B4 C2 C4 C0</pre><span class="anchor" id="line-208"></span><span class="anchor" id="line-209"></span><p class="line874">Matching sheets now gives <span class="anchor" id="line-210"></span><span class="anchor" id="line-211"></span><p class="line867"><span class="anchor" id="line-212"></span><span class="anchor" id="line-213"></span><span class="anchor" id="line-214"></span><pre><span class="anchor" id="line-1-18"></span>A1 A3 B1 B3 C1 C3 C6
<span class="anchor" id="line-2-6"></span>A2 A0 B2 B4 C2 C4 C0</pre><span class="anchor" id="line-215"></span><span class="anchor" id="line-216"></span><p class="line862">With <tt class="backtick">pdftopdf</tt> from <em>cupsfilters 1.0.55-1</em> or newer this <a href="/Tea4CUPS#manualdup-2">is done automatically</a>, so on jessie and stretch you do not have to think about it. If your <tt class="backtick">pdftopdf</tt> is from an older version of cupsfilters or is <a href="/DissectingandDebuggingtheCUPSPrintingSystem#pdfcentric">not part of the filtering chain</a> it is not done. <tt class="backtick">pdftopdf</tt> would not be used for a raw queue or (prior to cups-filters 1.10.0) a queue where a PostScript file is being sent to a PostScript printer. <span class="anchor" id="line-217"></span><span class="anchor" id="line-218"></span><p class="line862">Using <em>Tea4CUPS</em> the wanted blank pages can be inserted by having a hook script send a form feed to the printer when printing the even numbered pages in a <span class="anchor" id="line-219"></span>document containing an odd number of pages. Whether the total number of pages in a document is odd or even can be determined with the help of <a class="interwiki" href="https://manpages.debian.org/man/pkpgcounter" title="DebianMan">pkpgcounter</a>. <span class="anchor" id="line-220"></span><span class="anchor" id="line-221"></span><p class="line874">Set up virtq <span class="anchor" id="line-222"></span><span class="anchor" id="line-223"></span><p class="line867"><span class="anchor" id="line-224"></span><span class="anchor" id="line-225"></span><pre><span class="anchor" id="line-1-19"></span>lpadmin -p virtq -v tea4cups:// -E -m raw</pre><span class="anchor" id="line-226"></span><span class="anchor" id="line-227"></span><p class="line874">Have <span class="anchor" id="line-228"></span><span class="anchor" id="line-229"></span><p class="line867"><span class="anchor" id="line-230"></span><span class="anchor" id="line-231"></span><pre><span class="anchor" id="line-1-20"></span>prehook_manualduplex : /usr/local/bin/manualduplex $TEADATAFILE</pre><span class="anchor" id="line-232"></span><span class="anchor" id="line-233"></span><p class="line862">as a hook in <em>/etc/cups/tea4cups.conf</em> and use the following for <em>/usr/local/bin/manualduplex</em>: <span class="anchor" id="line-234"></span><span class="anchor" id="line-235"></span><p class="line867"><span class="anchor" id="line-236"></span><span class="anchor" id="line-237"></span><span class="anchor" id="line-238"></span><span class="anchor" id="line-239"></span><span class="anchor" id="line-240"></span><span class="anchor" id="line-241"></span><span class="anchor" id="line-242"></span><span class="anchor" id="line-243"></span><span class="anchor" id="line-244"></span><span class="anchor" id="line-245"></span><span class="anchor" id="line-246"></span><span class="anchor" id="line-247"></span><span class="anchor" id="line-248"></span><span class="anchor" id="line-249"></span><span class="anchor" id="line-250"></span><span class="anchor" id="line-251"></span><span class="anchor" id="line-252"></span><span class="anchor" id="line-253"></span><span class="anchor" id="line-254"></span><span class="anchor" id="line-255"></span><span class="anchor" id="line-256"></span><span class="anchor" id="line-257"></span><span class="anchor" id="line-258"></span><span class="anchor" id="line-259"></span><pre><span class="anchor" id="line-1-21"></span>#!/bin/bash
<span class="anchor" id="line-2-7"></span>
<span class="anchor" id="line-3-4"></span># Are we printing the document's odd or even pages?
<span class="anchor" id="line-4-3"></span>PAGESET=$(echo $TEAOPTIONS | grep -o &quot;page-set.*&quot; | cut -d&quot;=&quot; -f2 | cut -d&quot; &quot; -f1)
<span class="anchor" id="line-5-3"></span># Number of pages in the document.
<span class="anchor" id="line-6-3"></span>PAGES=$(pkpgcounter $1)
<span class="anchor" id="line-7-3"></span># Has the document an odd or even number of pages?
<span class="anchor" id="line-8-3"></span>REM=$(($PAGES % 2))
<span class="anchor" id="line-9-3"></span># Print queue.
<span class="anchor" id="line-10-3"></span>PRINTQ=realq
<span class="anchor" id="line-11-1"></span># Command for printing.
<span class="anchor" id="line-12-1"></span>PRINT=(/usr/bin/lp -d $PRINTQ -o &quot;$TEAOPTIONS&quot; $1)
<span class="anchor" id="line-13-1"></span>
<span class="anchor" id="line-14-1"></span>case $PAGESET in
<span class="anchor" id="line-15"></span>     even) case $REM in
<span class="anchor" id="line-16"></span>               0) &quot;${PRINT[@]}&quot;                 ;;
<span class="anchor" id="line-17"></span>               1) &quot;${PRINT[@]}&quot;
<span class="anchor" id="line-18"></span>                  # Form feed.
<span class="anchor" id="line-19"></span>                  echo -en &quot;\f&quot; | lp -d $PRINTQ ;;
<span class="anchor" id="line-20"></span>           esac                                 ;;
<span class="anchor" id="line-21"></span>        *) &quot;${PRINT[@]}&quot;                        ;;
<span class="anchor" id="line-22"></span>esac</pre><span class="anchor" id="line-260"></span><span class="anchor" id="line-261"></span><p class="line862">realq is set up as described <a href="/Tea4CUPS#Capturing_an_Input_File">here</a>. <span class="anchor" id="line-262"></span><span class="anchor" id="line-263"></span><p class="line874">Printing from an application is a matter of selecting the printer virtq, choosing odd numbered pages and printing them in reverse order, followed by printing even numbered pages. Otherwise, there is: <span class="anchor" id="line-264"></span><span class="anchor" id="line-265"></span><p class="line867"><span class="anchor" id="line-266"></span><span class="anchor" id="line-267"></span><span class="anchor" id="line-268"></span><pre><span class="anchor" id="line-1-22"></span>lp -d virtq -o 'outputorder=reverse page-set=odd' &lt;files&gt;
<span class="anchor" id="line-2-8"></span>lp -d virtq -o 'page-set=even' &lt;files&gt;</pre><span class="anchor" id="line-269"></span><span class="anchor" id="line-270"></span><p class="line867"><span class="anchor" id="manualdup-2"></span> <span class="anchor" id="line-271"></span>
<h3 id="Manual_Duplexing_.282.29">Manual Duplexing (2)</h3>
<span class="anchor" id="line-272"></span><span class="anchor" id="line-273"></span><p class="line874">Some printers offer the option of automatically printing on both sides of a sheet of paper (automatic duplex printing) without user intervention. Without automatic duplexing a user has to resort to manual duplexing; that is, printing the odd-numbered pages followed by the even-numbered ones after returning the sheets to the paper tray. The aim in this section is to make this as painless as possible by automating the printing process, leaving the user to concentrate on  getting the reinsertion of sheets in the printer tray correct. <span class="anchor" id="line-274"></span><span class="anchor" id="line-275"></span><p class="line874">The context for the scripts presented here is <span class="anchor" id="line-276"></span><span class="anchor" id="line-277"></span><ul><li>A printer which dumps a printout face up in the output tray and with the top of the page being at the leading edge. <span class="anchor" id="line-278"></span><span class="anchor" id="line-279"></span></li><li class="gap"><p class="line862">Using  <tt class="backtick">pdftopdf</tt> from <em>cupsfilters 1.0.55-1</em> or a later version. <span class="anchor" id="line-280"></span><span class="anchor" id="line-281"></span></li></ul><p class="line874">Set up virtq-duplex <span class="anchor" id="line-282"></span><span class="anchor" id="line-283"></span><p class="line867"><span class="anchor" id="line-284"></span><span class="anchor" id="line-285"></span><pre><span class="anchor" id="line-1-23"></span>lpadmin -p virtq-duplex -v tea4cups:// -E -m raw</pre><span class="anchor" id="line-286"></span><span class="anchor" id="line-287"></span><p class="line862">and in <em>/etc/cups/tea4cups.conf</em> have <span class="anchor" id="line-288"></span><span class="anchor" id="line-289"></span><p class="line867"><span class="anchor" id="line-290"></span><span class="anchor" id="line-291"></span><span class="anchor" id="line-292"></span><pre><span class="anchor" id="line-1-24"></span>[virtq-duplex]
<span class="anchor" id="line-2-9"></span>prehook_manualduplex : /usr/local/bin/mandup-tea4cups</pre><span class="anchor" id="line-293"></span><span class="anchor" id="line-294"></span><p class="line862">The content of <em>/usr/local/bin/mandup-tea4cups</em> is: <span class="anchor" id="line-295"></span><span class="anchor" id="line-296"></span><p class="line867"><span class="anchor" id="line-297"></span><span class="anchor" id="line-298"></span><span class="anchor" id="line-299"></span><span class="anchor" id="line-300"></span><span class="anchor" id="line-301"></span><span class="anchor" id="line-302"></span><span class="anchor" id="line-303"></span><span class="anchor" id="line-304"></span><span class="anchor" id="line-305"></span><span class="anchor" id="line-306"></span><span class="anchor" id="line-307"></span><span class="anchor" id="line-308"></span><span class="anchor" id="line-309"></span><pre><span class="anchor" id="line-1-25"></span>#!/bin/bash
<span class="anchor" id="line-2-10"></span>
<span class="anchor" id="line-3-5"></span># Tea4CUPS deletes $TEADATAFILE after printing the first set of pages.
<span class="anchor" id="line-4-4"></span># We need to have $TEADATAFILE to print the second set.
<span class="anchor" id="line-5-4"></span>cp $TEADATAFILE /tmp/job
<span class="anchor" id="line-6-4"></span># The user needs access to $TEADATAFILE.
<span class="anchor" id="line-7-4"></span>chown $TEAUSERNAME:$TEAUSERNAME /tmp/job
<span class="anchor" id="line-8-4"></span># realq does the actual printing. Adjust -o as necessary.
<span class="anchor" id="line-9-4"></span>lp -d realq -o 'outputorder=reverse page-set=odd' $TEADATAFILE
<span class="anchor" id="line-10-4"></span># A popup window using the dialog utility.
<span class="anchor" id="line-11-2"></span>LANG=C XAUTHORITY=/home/$TEAUSERNAME/.Xauthority DISPLAY=:0 xterm -geometry 80x30+0+0 -fa DejaVuSansMono -e /usr/local/bin/mandup-dialog /tmp/job</pre><span class="anchor" id="line-310"></span><span class="anchor" id="line-311"></span><p class="line862">Print the first set of pages from an application displaying <em>virtq-duplex</em> in its print dialog or with <span class="anchor" id="line-312"></span><span class="anchor" id="line-313"></span><p class="line867"><span class="anchor" id="line-314"></span><span class="anchor" id="line-315"></span><pre><span class="anchor" id="line-1-26"></span>lp -d virtq-duplex &lt;file&gt;</pre><span class="anchor" id="line-316"></span><span class="anchor" id="line-317"></span><p class="line874">and print the second set from the popup window after reading the instructions given. <span class="anchor" id="line-318"></span><span class="anchor" id="line-319"></span><p class="line862">The <a class="interwiki" href="https://manpages.debian.org/man/dialog" title="DebianMan">dialog utility</a> needs to be installed to use the script <em>/usr/local/bin/mandup-dialog</em> below. <a class="interwiki" href="https://manpages.debian.org/man/yad" title="DebianMan">yad</a> and <a class="interwiki" href="https://manpages.debian.org/man/zenity" title="DebianMan">zenity</a> are GUI alternatives to <tt class="backtick">dialog</tt> but will require the script to be adjusted. <span class="anchor" id="line-320"></span><span class="anchor" id="line-321"></span><p class="line867"><span class="anchor" id="line-322"></span><span class="anchor" id="line-323"></span><span class="anchor" id="line-324"></span><span class="anchor" id="line-325"></span><span class="anchor" id="line-326"></span><span class="anchor" id="line-327"></span><span class="anchor" id="line-328"></span><span class="anchor" id="line-329"></span><span class="anchor" id="line-330"></span><span class="anchor" id="line-331"></span><span class="anchor" id="line-332"></span><span class="anchor" id="line-333"></span><span class="anchor" id="line-334"></span><span class="anchor" id="line-335"></span><span class="anchor" id="line-336"></span><span class="anchor" id="line-337"></span><span class="anchor" id="line-338"></span><span class="anchor" id="line-339"></span><span class="anchor" id="line-340"></span><span class="anchor" id="line-341"></span><span class="anchor" id="line-342"></span><span class="anchor" id="line-343"></span><span class="anchor" id="line-344"></span><span class="anchor" id="line-345"></span><span class="anchor" id="line-346"></span><span class="anchor" id="line-347"></span><span class="anchor" id="line-348"></span><pre><span class="anchor" id="line-1-27"></span>#!/bin/bash
<span class="anchor" id="line-2-11"></span>
<span class="anchor" id="line-3-6"></span>printeven() {
<span class="anchor" id="line-4-5"></span>case $choice in
<span class="anchor" id="line-5-5"></span>        1) lp -d realq -o 'page-set=even outputorder=reverse' &quot;/tmp/job&quot; ; rm &quot;/tmp/job&quot;
<span class="anchor" id="line-6-5"></span>        ;;
<span class="anchor" id="line-7-5"></span>esac
<span class="anchor" id="line-8-5"></span>}
<span class="anchor" id="line-9-5"></span>
<span class="anchor" id="line-10-5"></span>dialog --backtitle &quot;Manual duplex: print even-numbered pages&quot; \
<span class="anchor" id="line-11-3"></span>--radiolist &quot;The odd-numbered pages are now being printed.\n\nWhen that \
<span class="anchor" id="line-12-2"></span>job is finished, return the printed sheets to the paper tray with the \
<span class="anchor" id="line-13-2"></span>blank sides of the paper facing you and the leading edges inserted into \
<span class="anchor" id="line-14-2"></span>the tray first. \n\nPress the ENTER key or use the mouse to click on OK \
<span class="anchor" id="line-15-1"></span>to print the even-numbered pages. \n\nThe Cancel button can be used if \
<span class="anchor" id="line-16-1"></span>there is only a single page for the job.&quot; 20 60 25 \
<span class="anchor" id="line-17-1"></span>1  &quot;Print even-numbered pages.&quot; on 2&gt; /tmp/menuchoice.$$
<span class="anchor" id="line-18-1"></span>
<span class="anchor" id="line-19-1"></span>sel=$?
<span class="anchor" id="line-20-1"></span>choice=$(cat /tmp/menuchoice.$$)
<span class="anchor" id="line-21-1"></span>case $sel in
<span class="anchor" id="line-22-1"></span>    0) printeven ; rm /tmp/menuchoice.$$ ; clear ;;
<span class="anchor" id="line-23"></span>    1) clear                                     ;;
<span class="anchor" id="line-24"></span>  255)                                           ;;
<span class="anchor" id="line-25"></span>esac</pre><span class="anchor" id="line-349"></span><span class="anchor" id="line-350"></span><p class="line867"><span class="anchor" id="manualdup-3"></span> <span class="anchor" id="line-351"></span>
<h3 id="Manual_Duplexing_.283.29">Manual Duplexing (3)</h3>
<span class="anchor" id="line-352"></span><span class="anchor" id="line-353"></span><p class="line862">This is a variation on the <a href="/Tea4CUPS#manualdup-2">previous technique</a> which, besides allowing manual duplexing, gives an output in booklet format. <a class="interwiki" href="https://manpages.debian.org/man/cupsfilter" title="DebianMan">cupsfilter</a> first produces a PDF using the <em>booklet</em> feature of <a href="/pdftopdfandPageRotation#bonus">pdftopdf</a>. Then the odd-numbered pages in the PDF, followed by the even-numbered pages, are printed. <span class="anchor" id="line-354"></span><span class="anchor" id="line-355"></span><p class="line874">Reinserting the paper in the printer might require some thought. For a printer which puts a printed sheet in the output tray face up, hold the long edges of the sheets in both hands and rotate them 180 degrees to have the non-printed sides facing you and the leading edges at the top. Insert the non-leading edges into the printer's input tray. <span class="anchor" id="line-356"></span><span class="anchor" id="line-357"></span><p class="line867"><span class="anchor" id="line-358"></span><span class="anchor" id="line-359"></span><span class="anchor" id="line-360"></span><span class="anchor" id="line-361"></span><span class="anchor" id="line-362"></span><span class="anchor" id="line-363"></span><span class="anchor" id="line-364"></span><span class="anchor" id="line-365"></span><span class="anchor" id="line-366"></span><span class="anchor" id="line-367"></span><span class="anchor" id="line-368"></span><span class="anchor" id="line-369"></span><pre><span class="anchor" id="line-1-28"></span>                                          Leading edges 
<span class="anchor" id="line-2-12"></span>        +---------+                        +---------+
<span class="anchor" id="line-3-7"></span>        |         |                        |         |
<span class="anchor" id="line-4-6"></span>        | Printed |                        |  Blank  |
<span class="anchor" id="line-5-6"></span>Left---&gt;|         |&lt;---Right       Left---&gt;|         |&lt;---Right
<span class="anchor" id="line-6-6"></span>hand    |         |    hand        hand    |         |    hand
<span class="anchor" id="line-7-6"></span>        |         |                        |         |
<span class="anchor" id="line-8-6"></span>        +---------+                        +---------+
<span class="anchor" id="line-9-6"></span>       Leading edges                    Insert this edge
<span class="anchor" id="line-10-6"></span>                                          into Printer  </pre><span class="anchor" id="line-370"></span><span class="anchor" id="line-371"></span><p class="line874">Set up virtq-duplex-booklet <span class="anchor" id="line-372"></span><span class="anchor" id="line-373"></span><p class="line867"><span class="anchor" id="line-374"></span><span class="anchor" id="line-375"></span><pre><span class="anchor" id="line-1-29"></span>lpadmin -p virtq-duplex-booklet -v tea4cups:// -E -m raw</pre><span class="anchor" id="line-376"></span><span class="anchor" id="line-377"></span><p class="line862">and in <em>/etc/cups/tea4cups.conf</em> have <span class="anchor" id="line-378"></span><span class="anchor" id="line-379"></span><p class="line867"><span class="anchor" id="line-380"></span><span class="anchor" id="line-381"></span><span class="anchor" id="line-382"></span><pre><span class="anchor" id="line-1-30"></span>[virtq-duplex-booklet]
<span class="anchor" id="line-2-13"></span>prehook_manualduplex-booklet : /usr/local/bin/mandup-tea4cups-booklet</pre><span class="anchor" id="line-383"></span><span class="anchor" id="line-384"></span><p class="line862">The content of <em>/usr/local/bin/mandup-tea4cups</em> is: <span class="anchor" id="line-385"></span><span class="anchor" id="line-386"></span><p class="line867"><span class="anchor" id="line-387"></span><span class="anchor" id="line-388"></span><span class="anchor" id="line-389"></span><span class="anchor" id="line-390"></span><span class="anchor" id="line-391"></span><span class="anchor" id="line-392"></span><span class="anchor" id="line-393"></span><span class="anchor" id="line-394"></span><span class="anchor" id="line-395"></span><span class="anchor" id="line-396"></span><span class="anchor" id="line-397"></span><span class="anchor" id="line-398"></span><pre><span class="anchor" id="line-1-31"></span>#!/bin/bash
<span class="anchor" id="line-2-14"></span>
<span class="anchor" id="line-3-8"></span># Produce booklet.
<span class="anchor" id="line-4-7"></span>/usr/sbin/cupsfilter -m application/vnd.cups-pdf -o booklet $TEADATAFILE 2&gt;/dev/null  &gt; /tmp/booklet.pdf
<span class="anchor" id="line-5-7"></span># Give the user access to the PDF.
<span class="anchor" id="line-6-7"></span>chown $TEAUSERNAME:$TEAUSERNAME /tmp/booklet.pdf
<span class="anchor" id="line-7-7"></span># Print odd-numbered pages on realq.
<span class="anchor" id="line-8-7"></span>lp -d realq -o 'page-set=odd' /tmp/booklet.pdf
<span class="anchor" id="line-9-7"></span># Popup window.
<span class="anchor" id="line-10-7"></span>LANG=C XAUTHORITY=/home/$TEAUSERNAME/.Xauthority DISPLAY=:0 xterm -geometry 80x30+0+0 -fa DejaVuSansMono -e /usr/local/bin/mandup-dialog /tmp/booklet.pdf</pre><span class="anchor" id="line-399"></span><span class="anchor" id="line-400"></span><p class="line862">The popup window needs the <a class="interwiki" href="https://manpages.debian.org/man/dialog" title="DebianMan">dialog utility</a> to be installed to use the script <em>/usr/local/bin/mandup-dialog-booklet</em> below. <a class="interwiki" href="https://manpages.debian.org/man/yad" title="DebianMan">yad</a> and <a class="interwiki" href="https://manpages.debian.org/man/zenity" title="DebianMan">zenity</a> are GUI alternatives to <tt class="backtick">dialog</tt> but will require the script to be adjusted. <span class="anchor" id="line-401"></span><span class="anchor" id="line-402"></span><p class="line867"><span class="anchor" id="line-403"></span><span class="anchor" id="line-404"></span><span class="anchor" id="line-405"></span><span class="anchor" id="line-406"></span><span class="anchor" id="line-407"></span><span class="anchor" id="line-408"></span><span class="anchor" id="line-409"></span><span class="anchor" id="line-410"></span><span class="anchor" id="line-411"></span><span class="anchor" id="line-412"></span><span class="anchor" id="line-413"></span><span class="anchor" id="line-414"></span><span class="anchor" id="line-415"></span><span class="anchor" id="line-416"></span><span class="anchor" id="line-417"></span><span class="anchor" id="line-418"></span><span class="anchor" id="line-419"></span><span class="anchor" id="line-420"></span><span class="anchor" id="line-421"></span><span class="anchor" id="line-422"></span><span class="anchor" id="line-423"></span><span class="anchor" id="line-424"></span><span class="anchor" id="line-425"></span><span class="anchor" id="line-426"></span><span class="anchor" id="line-427"></span><span class="anchor" id="line-428"></span><span class="anchor" id="line-429"></span><pre><span class="anchor" id="line-1-32"></span>#!/bin/bash
<span class="anchor" id="line-2-15"></span>
<span class="anchor" id="line-3-9"></span>printeven() {
<span class="anchor" id="line-4-8"></span>case $choice in
<span class="anchor" id="line-5-8"></span>        1) lp -d realq -o 'page-set=even' &quot;/tmp/booklet.pdf&quot; ; rm &quot;/tmp/booklet.pdf&quot;
<span class="anchor" id="line-6-8"></span>        ;;
<span class="anchor" id="line-7-8"></span>esac
<span class="anchor" id="line-8-8"></span>}
<span class="anchor" id="line-9-8"></span>
<span class="anchor" id="line-10-8"></span>dialog --backtitle &quot;Manual duplex: print even-numbered pages&quot; \
<span class="anchor" id="line-11-4"></span>--radiolist &quot;The odd-numbered pages are now being printed.\n\nWhen that \
<span class="anchor" id="line-12-3"></span>job is finished, return the printed sheets to the paper tray with the \
<span class="anchor" id="line-13-3"></span>blank sides of the paper facing you and the non-leading edges inserted into \
<span class="anchor" id="line-14-3"></span>the tray first. \n\nPress the ENTER key or use the mouse to click on OK \
<span class="anchor" id="line-15-2"></span>to print the even-numbered pages. \n\nThe Cancel button can be used if \
<span class="anchor" id="line-16-2"></span>there is only a single page for the job.&quot; 20 60 25 \
<span class="anchor" id="line-17-2"></span>1  &quot;Print even-numbered pages.&quot; on 2&gt; /tmp/menuchoice.$$
<span class="anchor" id="line-18-2"></span>
<span class="anchor" id="line-19-2"></span>sel=$?
<span class="anchor" id="line-20-2"></span>choice=$(cat /tmp/menuchoice.$$)
<span class="anchor" id="line-21-2"></span>case $sel in
<span class="anchor" id="line-22-2"></span>    0) printeven ; rm /tmp/menuchoice.$$ ; clear ;;
<span class="anchor" id="line-23-1"></span>    1) clear                                     ;;
<span class="anchor" id="line-24-1"></span>  255)                                           ;;
<span class="anchor" id="line-25-1"></span>esac</pre><span class="anchor" id="line-430"></span><span class="anchor" id="line-431"></span><span class="anchor" id="line-432"></span><span class="anchor" id="line-433"></span><span class="anchor" id="line-434"></span><p class="line867"><span class="anchor" id="microsoft"></span> <span class="anchor" id="line-435"></span>
<h3 id="Printing_Microsoft_Documents">Printing Microsoft Documents</h3>
<span class="anchor" id="line-436"></span><span class="anchor" id="line-437"></span><p class="line874">The technique is based on converting the document to a PDF via a prehook <span class="anchor" id="line-438"></span>and a script and then submitting the PDF to a print queue, realq. <a class="interwiki" href="https://manpages.debian.org/man/unoconv" title="DebianMan">unoconv</a> does the conversion. Its installation will bring in a number of Libreoffice packages but X is not required because unoconv can be started as a listener for unconv clients. For listening permanently <span class="anchor" id="line-439"></span>in the background: <span class="anchor" id="line-440"></span><span class="anchor" id="line-441"></span><p class="line867"><span class="anchor" id="line-442"></span><span class="anchor" id="line-443"></span><pre><span class="anchor" id="line-1-33"></span>  unconv -l &amp;</pre><span class="anchor" id="line-444"></span><span class="anchor" id="line-445"></span><p class="line874">A prehook would call the script with <span class="anchor" id="line-446"></span><span class="anchor" id="line-447"></span><p class="line867"><span class="anchor" id="line-448"></span><span class="anchor" id="line-449"></span><pre><span class="anchor" id="line-1-34"></span>   prehook_unoconv : /usr/local/bin/print-office-docs $TEADATAFILE</pre><span class="anchor" id="line-450"></span><span class="anchor" id="line-451"></span><p class="line874">and invoke <span class="anchor" id="line-452"></span><span class="anchor" id="line-453"></span><p class="line867"><span class="anchor" id="line-454"></span><span class="anchor" id="line-455"></span><span class="anchor" id="line-456"></span><span class="anchor" id="line-457"></span><span class="anchor" id="line-458"></span><span class="anchor" id="line-459"></span><span class="anchor" id="line-460"></span><span class="anchor" id="line-461"></span><span class="anchor" id="line-462"></span><span class="anchor" id="line-463"></span><span class="anchor" id="line-464"></span><span class="anchor" id="line-465"></span><span class="anchor" id="line-466"></span><span class="anchor" id="line-467"></span><span class="anchor" id="line-468"></span><span class="anchor" id="line-469"></span><span class="anchor" id="line-470"></span><span class="anchor" id="line-471"></span><span class="anchor" id="line-472"></span><span class="anchor" id="line-473"></span><span class="anchor" id="line-474"></span><span class="anchor" id="line-475"></span><span class="anchor" id="line-476"></span><span class="anchor" id="line-477"></span><span class="anchor" id="line-478"></span><span class="anchor" id="line-479"></span><pre><span class="anchor" id="line-1-35"></span>  #!/bin/bash
<span class="anchor" id="line-2-16"></span>  #!/bin/bash
<span class="anchor" id="line-3-10"></span>
<span class="anchor" id="line-4-9"></span>  # The working directory and filename.
<span class="anchor" id="line-5-9"></span>  OUT=$TEADIRECTORY/tmp/tea4cups-$TEAJOBID-$TEATITLE.pdf
<span class="anchor" id="line-6-9"></span>
<span class="anchor" id="line-7-9"></span>  UNO=/usr/bin/unoconv
<span class="anchor" id="line-8-9"></span>  MIMETYPE=$(file --mime-type -b $1)
<span class="anchor" id="line-9-9"></span>  PPT=application/vnd.ms-powerpoint
<span class="anchor" id="line-10-9"></span>  DOC=application/msword
<span class="anchor" id="line-11-5"></span>  DOCX=application/vnd.openxmlformats-officedocument.wordprocessingml.document
<span class="anchor" id="line-12-4"></span>  RTF=text/rtf
<span class="anchor" id="line-13-4"></span>  ODT=application/vnd.oasis.opendocument.text
<span class="anchor" id="line-14-4"></span>
<span class="anchor" id="line-15-3"></span>  # Have &quot;*)&quot; exit with an error message?
<span class="anchor" id="line-16-3"></span>  case $MIMETYPE in
<span class="anchor" id="line-17-3"></span>     $PPT|$DOC|$DOCX|$RTF|$ODT) $UNO -o $OUT $1
<span class="anchor" id="line-18-3"></span>                                lp -d realq -o &quot;$TEAOPTIONS&quot; $OUT
<span class="anchor" id="line-19-3"></span>                                rm $OUT
<span class="anchor" id="line-20-3"></span>                                  ;;
<span class="anchor" id="line-21-3"></span>                             *) lp -d realq -o &quot;$TEAOPTIONS&quot; $1
<span class="anchor" id="line-22-3"></span>                                  ;;
<span class="anchor" id="line-23-2"></span>  esac</pre><span class="anchor" id="line-480"></span><p class="line862">Print queues virtq and realq are set up as indicated in <a href="/Tea4CUPS#Capturing_an_Input_File">the previous section</a>. The usual command line, without any options, would be: <span class="anchor" id="line-481"></span><span class="anchor" id="line-482"></span><p class="line867"><span class="anchor" id="line-483"></span><span class="anchor" id="line-484"></span><pre><span class="anchor" id="line-1-36"></span>  lp -d virtq &lt;office_file&gt;</pre><span class="anchor" id="line-485"></span><span class="anchor" id="line-486"></span><p class="line874">What should happen if the file is not an office-type file is open to <span class="anchor" id="line-487"></span>configuration in the script. <span class="anchor" id="line-488"></span><span class="anchor" id="line-489"></span><p class="line867"><span class="anchor" id="selectedfont"></span> <span class="anchor" id="line-490"></span>
<h3 id="Text_to_PDF_with_a_Selected_Font">Text to PDF with a Selected Font</h3>
<span class="anchor" id="line-491"></span><span class="anchor" id="line-492"></span><p class="line862">On the <a href="/ThetexttopdfFilter">texttopdf page</a> we see that a font for printing text files can be selected by fontconfig or specified as a system-wide or user default. If a text file is sent to a remote server the font used for printing is determined by what happens on the server. One solution to having a text file printed with a client's chosen font is first to convert it to a PDF which has the fonts embedded in it. It is the PDF which is sent to the server. <span class="anchor" id="line-493"></span><span class="anchor" id="line-494"></span><p class="line874">The same technique (converting a text file to a PDF) can also be used when sending a file to both local and remote print queues and wanting to choose a font for the job. This is the approach taken in the following script. <span class="anchor" id="line-495"></span><span class="anchor" id="line-496"></span><p class="line862">Suppose the choice available for a monospaced font is one of <a class="interwiki" href="https://packages.debian.org/fonts-freefont-ttf" title="DebianPkg">FreeMono</a> and <a class="interwiki" href="https://packages.debian.org/fonts-dejavu-core" title="DebianPkg">DejaVusansMono</a>. Create the files <em>pdf.freemono</em> and <em>pdf.dejavu</em> in <em>$HOME/charsets</em>: <span class="anchor" id="line-497"></span><span class="anchor" id="line-498"></span><p class="line867"><span class="anchor" id="line-499"></span><span class="anchor" id="line-500"></span><span class="anchor" id="line-501"></span><span class="anchor" id="line-502"></span><pre><span class="anchor" id="line-1-37"></span># pdf.freemono
<span class="anchor" id="line-2-17"></span>charset utf8
<span class="anchor" id="line-3-11"></span>0000 04FF ltor single /usr/share/fonts/truetype/freemono/FreeMono.ttf</pre><span class="anchor" id="line-503"></span><span class="anchor" id="line-504"></span><p class="line867"><span class="anchor" id="line-505"></span><span class="anchor" id="line-506"></span><span class="anchor" id="line-507"></span><span class="anchor" id="line-508"></span><pre><span class="anchor" id="line-1-38"></span># pdf.dejavu
<span class="anchor" id="line-2-18"></span>charset utf8
<span class="anchor" id="line-3-12"></span>0000 04FF ltor single /usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf</pre><span class="anchor" id="line-509"></span><span class="anchor" id="line-510"></span><p class="line862">The command for converting a text file to a PDF file having the FreeMono font on the client machine is: <span class="anchor" id="line-511"></span><span class="anchor" id="line-512"></span><p class="line867"><span class="anchor" id="line-513"></span><span class="anchor" id="line-514"></span><pre><span class="anchor" id="line-1-39"></span>CUPS_DATADIR=$HOME CHARSET=freemono /usr/lib/cups/filter/texttopdf 0 0 0 0 0 in.txt &gt; out.pd</pre><span class="anchor" id="line-515"></span><span class="anchor" id="line-516"></span><p class="line862">This causes texttopdf to look for the file <em>pdf.freemono</em> in the charsets directory of <em>$CUPS_DATADIR</em>. <em>$CUPS_DATADIR</em> would normally be <span class="anchor" id="line-517"></span><em>/usr/share/cups/</em> but texttopdf will now look for the character set in a <span class="anchor" id="line-518"></span>charsets directory in the home directory. This command is used in the script below. Note that there the environment variables <em>$CUPS_DATADIR</em> and <em>$CHARSET</em> are set up prior to invoking <em>/usr/lib/cups/filter/texttopdf</em>. <span class="anchor" id="line-519"></span><span class="anchor" id="line-520"></span><p class="line862">We can now proceed with setting up a <a href="/Tea4CUPS#capturing">raw virtual queue</a> and using <span class="anchor" id="line-521"></span>the prehook line: <span class="anchor" id="line-522"></span><span class="anchor" id="line-523"></span><p class="line867"><span class="anchor" id="line-524"></span><span class="anchor" id="line-525"></span><pre><span class="anchor" id="line-1-40"></span>prehook_texttopdf : /usr/local/bin/texttopdf $TEADATAFILE</pre><span class="anchor" id="line-526"></span><span class="anchor" id="line-527"></span><p class="line874">A viable script for texttopdf is: <span class="anchor" id="line-528"></span><span class="anchor" id="line-529"></span><p class="line867"><span class="anchor" id="line-530"></span><span class="anchor" id="line-531"></span><span class="anchor" id="line-532"></span><span class="anchor" id="line-533"></span><span class="anchor" id="line-534"></span><span class="anchor" id="line-535"></span><span class="anchor" id="line-536"></span><span class="anchor" id="line-537"></span><span class="anchor" id="line-538"></span><span class="anchor" id="line-539"></span><span class="anchor" id="line-540"></span><span class="anchor" id="line-541"></span><span class="anchor" id="line-542"></span><span class="anchor" id="line-543"></span><span class="anchor" id="line-544"></span><span class="anchor" id="line-545"></span><span class="anchor" id="line-546"></span><span class="anchor" id="line-547"></span><span class="anchor" id="line-548"></span><span class="anchor" id="line-549"></span><span class="anchor" id="line-550"></span><span class="anchor" id="line-551"></span><span class="anchor" id="line-552"></span><span class="anchor" id="line-553"></span><span class="anchor" id="line-554"></span><span class="anchor" id="line-555"></span><pre><span class="anchor" id="line-1-41"></span>#!/bin/bash
<span class="anchor" id="line-2-19"></span>#!/bin/bash
<span class="anchor" id="line-3-13"></span>
<span class="anchor" id="line-4-10"></span># Detect whether the input file is text/plain.
<span class="anchor" id="line-5-10"></span>MIMETYPE=$(file --mime-type -b $1)
<span class="anchor" id="line-6-10"></span># The print queue to send the output PDF to.
<span class="anchor" id="line-7-10"></span>PRINTQ=realq
<span class="anchor" id="line-8-10"></span># The user's CUPS_DATADIR. Where the pdf.* files are.
<span class="anchor" id="line-9-10"></span>CUPS_DATADIR=/home/$TEAUSERNAME
<span class="anchor" id="line-10-10"></span># Font_name. Should be the &quot;*&quot; part of pdf.*.
<span class="anchor" id="line-11-6"></span>CHARSET=$(echo $TEAOPTIONS | grep -E -o &quot;font=[a-z]+&quot; | cut -d&quot;=&quot; -f2)
<span class="anchor" id="line-12-5"></span>
<span class="anchor" id="line-13-5"></span># The default pdf.utf-8.simple is used if the font option is empty or
<span class="anchor" id="line-14-5"></span># if the user specifies a font_name unknown to the files in $HOME/charsets.
<span class="anchor" id="line-15-4"></span>if [ -z &quot;$CHARSET&quot; ] ; then
<span class="anchor" id="line-16-4"></span>   CUPS_DATADIR=&quot;/usr/share/cups&quot; ; CHARSET=&quot;utf-8&quot;
<span class="anchor" id="line-17-4"></span>fi
<span class="anchor" id="line-18-4"></span>
<span class="anchor" id="line-19-4"></span>if [ -e &quot;$CUPS_DATADIR/charsets/pdf.$CHARSET&quot; ] &amp;&amp; [ $MIMETYPE = &quot;text/plain&quot; ]
<span class="anchor" id="line-20-4"></span>   then
<span class="anchor" id="line-21-4"></span>      /usr/lib/cups/filter/texttopdf 1 1 1 1 1 $1 | lp -d $PRINTQ
<span class="anchor" id="line-22-4"></span>   else
<span class="anchor" id="line-23-3"></span>     lp -d $PRINTQ $1
<span class="anchor" id="line-24-2"></span>fi</pre><span class="anchor" id="line-556"></span><span class="anchor" id="line-557"></span><p class="line874">Printing would be with <span class="anchor" id="line-558"></span><span class="anchor" id="line-559"></span><p class="line867"><span class="anchor" id="line-560"></span><span class="anchor" id="line-561"></span><pre><span class="anchor" id="line-1-42"></span>  lp -d virtq -o font=&lt;font_name&gt; &lt;text_file&gt;</pre><span class="anchor" id="line-562"></span><span class="anchor" id="line-563"></span><p class="line867"><span class="anchor" id="searchable1"></span> <span class="anchor" id="line-564"></span>
<h3 id="Creating_Searchable_PDFs_from_Text_Files_.281.29">Creating Searchable PDFs from Text Files (1)</h3>
<span class="anchor" id="line-565"></span><span class="anchor" id="line-566"></span><p class="line862">A PDF file produced with the texttopdf filter <a href="/Tea4CUPS#Text_to_PDF_with_a_Selected_Font">as in the previous section</a> is <a href="/ThetexttopdfFilter#Using_texttpdf_to_Produce_PDFs">not searchable</a>, so we will look at a way of creating such PDFs with Abiword and have Tea4CUPS send the output by mail to a user. <span class="anchor" id="line-567"></span><span class="anchor" id="line-568"></span><p class="line862">An X setup is not necessary if <a class="interwiki" href="https://manpages.debian.org/man/xvfb" title="DebianMan">xvfb</a> is installed. The first step <span class="anchor" id="line-569"></span>is to convert the text file to a .abw file, which then gets converted to the <span class="anchor" id="line-570"></span>wanted searchable PDF. <span class="anchor" id="line-571"></span><span class="anchor" id="line-572"></span><p class="line867"><span class="anchor" id="line-573"></span><span class="anchor" id="line-574"></span><span class="anchor" id="line-575"></span><span class="anchor" id="line-576"></span><pre><span class="anchor" id="line-1-43"></span>  xvfb-run abiword --to=abw --to-name=out.abw in.txt
<span class="anchor" id="line-2-20"></span>
<span class="anchor" id="line-3-14"></span>  xvfb-run abiword --to=pdf --to-name=searchable.pdf out.abw</pre><span class="anchor" id="line-577"></span><span class="anchor" id="line-578"></span><p class="line874">You are wondering why a conversion straight to PDF with --to=pdf isn't <span class="anchor" id="line-579"></span>being done? Well, it could be - but the PDF will have a serif font with a <span class="anchor" id="line-580"></span>12pt font and this may not be to your liking. <span class="anchor" id="line-581"></span><span class="anchor" id="line-582"></span><p class="line874">A .abw file is xml text so we lose nothing with taking this route and <span class="anchor" id="line-583"></span>gain the ability to have a configurable monospaced font by editing <span class="anchor" id="line-584"></span>out.abw. FontFamily= and FontSize= will be the options we will use with <span class="anchor" id="line-585"></span>lp. The FF and FS variables hold the command line -o values. Without <span class="anchor" id="line-586"></span>values for FontFamily and FontSize FreeMono at a 10pt font size is the <span class="anchor" id="line-587"></span>default for the PDF. <span class="anchor" id="line-588"></span><span class="anchor" id="line-589"></span><p class="line874">The Tea4CUPS variable TEABILLING is conscripted to allow an email <span class="anchor" id="line-590"></span>address to be specified on the command line. Without it the PDF file is <span class="anchor" id="line-591"></span>sent to the user's home directory on the machine the script runs on. <span class="anchor" id="line-592"></span><span class="anchor" id="line-593"></span><p class="line874">The script is: <span class="anchor" id="line-594"></span><span class="anchor" id="line-595"></span><p class="line867"><span class="anchor" id="line-596"></span><span class="anchor" id="line-597"></span><span class="anchor" id="line-598"></span><span class="anchor" id="line-599"></span><span class="anchor" id="line-600"></span><span class="anchor" id="line-601"></span><span class="anchor" id="line-602"></span><span class="anchor" id="line-603"></span><span class="anchor" id="line-604"></span><span class="anchor" id="line-605"></span><span class="anchor" id="line-606"></span><span class="anchor" id="line-607"></span><span class="anchor" id="line-608"></span><span class="anchor" id="line-609"></span><span class="anchor" id="line-610"></span><span class="anchor" id="line-611"></span><span class="anchor" id="line-612"></span><span class="anchor" id="line-613"></span><span class="anchor" id="line-614"></span><span class="anchor" id="line-615"></span><span class="anchor" id="line-616"></span><span class="anchor" id="line-617"></span><span class="anchor" id="line-618"></span><span class="anchor" id="line-619"></span><span class="anchor" id="line-620"></span><span class="anchor" id="line-621"></span><span class="anchor" id="line-622"></span><span class="anchor" id="line-623"></span><span class="anchor" id="line-624"></span><span class="anchor" id="line-625"></span><span class="anchor" id="line-626"></span><span class="anchor" id="line-627"></span><span class="anchor" id="line-628"></span><span class="anchor" id="line-629"></span><span class="anchor" id="line-630"></span><span class="anchor" id="line-631"></span><span class="anchor" id="line-632"></span><span class="anchor" id="line-633"></span><span class="anchor" id="line-634"></span><span class="anchor" id="line-635"></span><span class="anchor" id="line-636"></span><span class="anchor" id="line-637"></span><span class="anchor" id="line-638"></span><pre><span class="anchor" id="line-1-44"></span> #!/bin/bash
<span class="anchor" id="line-2-21"></span> #!/bin/bash
<span class="anchor" id="line-3-15"></span>
<span class="anchor" id="line-4-11"></span>  # Check for a text input file?
<span class="anchor" id="line-5-11"></span>  # Execute abiword without installing xorg.
<span class="anchor" id="line-6-11"></span>  XVFB=/usr/bin/xvfb-run
<span class="anchor" id="line-7-11"></span>  # Mail program.
<span class="anchor" id="line-8-11"></span>  MAIL=/usr/bin/mutt
<span class="anchor" id="line-9-11"></span>  # Mail subject.
<span class="anchor" id="line-10-11"></span>  SUBJ=&quot;Your requested PDF: $TEATITLE.pdf&quot;
<span class="anchor" id="line-11-7"></span>  # Where we work. And the filename we work with.
<span class="anchor" id="line-12-6"></span>  OUT=$TEADIRECTORY/tmp/tea4cups-$TEAUSERNAME-$TEATITLE
<span class="anchor" id="line-13-6"></span>  # Have we been given FontFamily and FontSize?
<span class="anchor" id="line-14-6"></span>  FF=$(echo $TEAOPTIONS | grep -o &quot;FontFamily.*&quot; | cut -d&quot;=&quot; -f2 | cut -d&quot; &quot; -f1)
<span class="anchor" id="line-15-5"></span>  FS=$(echo $TEAOPTIONS | grep -o &quot;FontSize.*&quot; | cut -d&quot;=&quot; -f2 | cut -d&quot; &quot; -f1)
<span class="anchor" id="line-16-5"></span>
<span class="anchor" id="line-17-5"></span>  # First convert the input file to a .abw (XML) file.
<span class="anchor" id="line-18-5"></span>  $XVFB abiword --to=abw --to-name=$OUT.abw $TEADATAFILE &gt; /dev/null
<span class="anchor" id="line-19-5"></span>
<span class="anchor" id="line-20-5"></span>  # Edit $OUT.abw for FontFamily ($FF) and FontSize ($FS).
<span class="anchor" id="line-21-5"></span>  case $FF in
<span class="anchor" id="line-22-5"></span>      &quot;&quot;) awk '{sub(&quot;Liberation Serif&quot;,&quot;FreeMono&quot;,$0); print $0}' $OUT.abw &gt; $OUT.FF.abw ;;
<span class="anchor" id="line-23-4"></span>       *) awk '{sub(&quot;Liberation Serif&quot;,&quot;'$FF'&quot;,$0); print $0}' $OUT.abw &gt; $OUT.FF.abw ;;
<span class="anchor" id="line-24-3"></span>  esac
<span class="anchor" id="line-25-2"></span>
<span class="anchor" id="line-26"></span>  case $FS in
<span class="anchor" id="line-27"></span>      &quot;&quot;) awk '{sub(&quot;font-size:12pt&quot;,&quot;font-size:10pt&quot;,$0); print $0}' $OUT.FF.abw &gt; $OUT.FS.abw ;;
<span class="anchor" id="line-28"></span>       *) awk '{sub(&quot;font-size:12pt&quot;,&quot;font-size:&quot;'$FS'&quot;pt&quot;); print $0}' $OUT.FF.abw &gt; $OUT.FS.abw ;;
<span class="anchor" id="line-29"></span>  esac
<span class="anchor" id="line-30"></span>
<span class="anchor" id="line-31"></span>  # Convert to a PDF.
<span class="anchor" id="line-32"></span>  xvfb-run abiword --to=pdf --to-name=$OUT.pdf $OUT.FS.abw &gt; /dev/null
<span class="anchor" id="line-33"></span>
<span class="anchor" id="line-34"></span>  if [ -z &quot;$TEABILLING&quot; ] ; then
<span class="anchor" id="line-35"></span>     $MAIL -s &quot;$SUBJ&quot; -a $OUT.pdf -- $TEAUSERNAME@localhost
<span class="anchor" id="line-36"></span>  else
<span class="anchor" id="line-37"></span>     $MAIL -s &quot;$SUBJ&quot; -a $OUT.pdf -- $TEABILLING
<span class="anchor" id="line-38"></span>  fi
<span class="anchor" id="line-39"></span>
<span class="anchor" id="line-40"></span>  # Clean up. /var/spool/cups/tmp/sent? Rely on /etc/logrotate.d/cups-daemon
<span class="anchor" id="line-41"></span>  # to clear /var/spool/cups/tmp/?
<span class="anchor" id="line-42"></span>  rm $OUT*</pre><span class="anchor" id="line-639"></span><span class="anchor" id="line-640"></span><p class="line874">The prehook line is: <span class="anchor" id="line-641"></span><span class="anchor" id="line-642"></span><p class="line867"><span class="anchor" id="line-643"></span><span class="anchor" id="line-644"></span><pre><span class="anchor" id="line-1-45"></span>  prehook_searchablepdf : /usr/local/bin/searchablepdf</pre><span class="anchor" id="line-645"></span><span class="anchor" id="line-646"></span><p class="line874">A command for printing would look like: <span class="anchor" id="line-647"></span><span class="anchor" id="line-648"></span><p class="line867"><span class="anchor" id="line-649"></span><span class="anchor" id="line-650"></span><pre><span class="anchor" id="line-1-46"></span>  lp -d virtq -o 'FontFamily=DroidSansMono FontSize=10 job-billing=user@example.com'</pre><span class="anchor" id="line-651"></span><span class="anchor" id="line-652"></span><p class="line867"><span class="anchor" id="searchable2"></span> <span class="anchor" id="line-653"></span>
<h3 id="Creating_Searchable_PDFs_from_Text_Files_.282.29">Creating Searchable PDFs from Text Files (2)</h3>
<span class="anchor" id="line-654"></span><span class="anchor" id="line-655"></span><p class="line862">This is an alternative to using <a href="/Tea4CUPS#searchable1">Abiword</a> and might be seen as easier and more straightforward to implement. It relies on <a class="interwiki" href="https://manpages.debian.org/man/pdftocairo" title="DebianMan">pdftocairo</a> to convert the PDF produced by the texttopdf filter into another PDF, which is searchable. The script is a simplified version of the one in a <a href="/Tea4CUPS#selectedfont">previous section</a> and pdftocairo performs the same task in a <a href="/Tea4CUPS#virt2">later script</a>. <span class="anchor" id="line-656"></span><span class="anchor" id="line-657"></span><p class="line867"><span class="anchor" id="line-658"></span><span class="anchor" id="line-659"></span><span class="anchor" id="line-660"></span><span class="anchor" id="line-661"></span><span class="anchor" id="line-662"></span><span class="anchor" id="line-663"></span><span class="anchor" id="line-664"></span><span class="anchor" id="line-665"></span><span class="anchor" id="line-666"></span><span class="anchor" id="line-667"></span><span class="anchor" id="line-668"></span><span class="anchor" id="line-669"></span><span class="anchor" id="line-670"></span><span class="anchor" id="line-671"></span><span class="anchor" id="line-672"></span><span class="anchor" id="line-673"></span><span class="anchor" id="line-674"></span><span class="anchor" id="line-675"></span><span class="anchor" id="line-676"></span><span class="anchor" id="line-677"></span><span class="anchor" id="line-678"></span><span class="anchor" id="line-679"></span><span class="anchor" id="line-680"></span><span class="anchor" id="line-681"></span><span class="anchor" id="line-682"></span><pre><span class="anchor" id="line-1-47"></span>#!/bin/bash
<span class="anchor" id="line-2-22"></span>#!/bin/bash
<span class="anchor" id="line-3-16"></span># texttopdf. Convert text files to searchable PDFs.
<span class="anchor" id="line-4-12"></span>
<span class="anchor" id="line-5-12"></span>MIMETYPE=$(file --mime-type -b $1)
<span class="anchor" id="line-6-12"></span>TTP=&quot;/usr/lib/cups/filter/texttopdf 1 1 1 1 1 $1&quot;
<span class="anchor" id="line-7-12"></span>DIR=&quot;/home/$TEAUSERNAME/PDF/&quot;
<span class="anchor" id="line-8-12"></span>PDF=&quot;$DIR/$TEATITLE.pdf&quot;
<span class="anchor" id="line-9-12"></span>TU=&quot;$TEAUSERNAME&quot;
<span class="anchor" id="line-10-12"></span>
<span class="anchor" id="line-11-8"></span># Create directory for PDFs if one does not exist.
<span class="anchor" id="line-12-7"></span>if [ ! -d &quot;$DIR&quot; ] ; then
<span class="anchor" id="line-13-7"></span>   mkdir &quot;$DIR&quot;
<span class="anchor" id="line-14-7"></span>   chown &quot;$TU&quot;:&quot;$TU&quot; &quot;$DIR&quot;
<span class="anchor" id="line-15-6"></span>fi
<span class="anchor" id="line-16-6"></span>
<span class="anchor" id="line-17-6"></span>if [ &quot;$MIMETYPE&quot; = &quot;text/plain&quot; ]
<span class="anchor" id="line-18-6"></span>   then
<span class="anchor" id="line-19-6"></span>      $TTP | pdftocairo -pdf - &quot;$PDF&quot;
<span class="anchor" id="line-20-6"></span>      chown &quot;$TU:$TU&quot; &quot;$PDF&quot;
<span class="anchor" id="line-21-6"></span>   else 
<span class="anchor" id="line-22-6"></span>      rm &quot;$TEADATAFILE&quot;
<span class="anchor" id="line-23-5"></span>fi</pre><span class="anchor" id="line-683"></span><span class="anchor" id="line-684"></span><p class="line862">A prehook for a <a href="/Tea4CUPS#capturing">virtual raw queue</a> would be <span class="anchor" id="line-685"></span><span class="anchor" id="line-686"></span><p class="line867"><span class="anchor" id="line-687"></span><span class="anchor" id="line-688"></span><pre><span class="anchor" id="line-1-48"></span>prehook_texttopdf : /usr/local/bin/texttopdf $TEADATAFILE</pre><span class="anchor" id="line-689"></span><span class="anchor" id="line-690"></span><p class="line867"><span class="anchor" id="virt1"></span> <span class="anchor" id="line-691"></span>
<h3 id="Virtual_PDF_Printer_.281.29">Virtual PDF Printer (1)</h3>
<span class="anchor" id="line-692"></span><span class="anchor" id="line-693"></span><p class="line874">Create a raw printer queue named TeaPDF: <span class="anchor" id="line-694"></span><span class="anchor" id="line-695"></span><p class="line867"><span class="anchor" id="line-696"></span><span class="anchor" id="line-697"></span><pre><span class="anchor" id="line-1-49"></span>lpadmin -p TeaPDF -v tea4cups:// -E -m raw</pre><span class="anchor" id="line-698"></span><span class="anchor" id="line-699"></span><p class="line874">Create pre and post hooks in /etc/cups/tea4cups.conf by adding the following lines at the end of the file: <span class="anchor" id="line-700"></span><span class="anchor" id="line-701"></span><p class="line867"><span class="anchor" id="line-702"></span><span class="anchor" id="line-703"></span><span class="anchor" id="line-704"></span><span class="anchor" id="line-705"></span><pre><span class="anchor" id="line-1-50"></span>[TeaPDF]
<span class="anchor" id="line-2-23"></span>prehook_rawpdf  : /bin/cat $TEADATAFILE |  su $TEAUSERNAME -l -c &quot;cat - &gt; `/usr/bin/getent passwd $TEAUSERNAME | /usr/bin/cut -f 6,6 -d :`'/PDF/job-$TEAJOBID-$TEATITLE.pdf'&quot;
<span class="anchor" id="line-3-17"></span>posthook_rawpdf : /bin/cat &gt;/tmp/log_of_pdf_creation_for_job_$TEAJOBID</pre><span class="anchor" id="line-706"></span><span class="anchor" id="line-707"></span><p class="line862">In the user's home directory create a new directory named PDF otherwise print jobs to TeaPDF will be aborted. Any print jobs sent to TeaPDF will be saved to the new PDF directory with the file name format, job-&lt;JOB-ID&gt;-&lt;TITLE&gt;.pdf. <span class="anchor" id="line-708"></span><span class="anchor" id="line-709"></span><p class="line867"><span class="anchor" id="virt2"></span> <span class="anchor" id="line-710"></span>
<h3 id="Virtual_PDF_Printer_.282.29">Virtual PDF Printer (2)</h3>
<span class="anchor" id="line-711"></span><span class="anchor" id="line-712"></span><p class="line862">It is very common for a user to use <a href="/SystemPrinting">cups-pdf</a> to convert a file to PDF format. Unfortunately, it is possible for the resulting PDFs (particularly from GTK applications) to be of <a class="interwiki" href="https://bugs.debian.org/847462" title="DebianBug">variable quality</a> and not have <a class="interwiki" href="https://bugs.launchpad.net/bugs/820820" title="UbuntuBug">searchable or extractable</a> text. The script below, <em>print-to-pdf</em>, is intended to remedy both these deficiencies. <span class="anchor" id="line-713"></span><span class="anchor" id="line-714"></span><p class="line867"><span class="anchor" id="line-715"></span><span class="anchor" id="line-716"></span><span class="anchor" id="line-717"></span><span class="anchor" id="line-718"></span><span class="anchor" id="line-719"></span><span class="anchor" id="line-720"></span><span class="anchor" id="line-721"></span><span class="anchor" id="line-722"></span><span class="anchor" id="line-723"></span><span class="anchor" id="line-724"></span><span class="anchor" id="line-725"></span><span class="anchor" id="line-726"></span><span class="anchor" id="line-727"></span><span class="anchor" id="line-728"></span><span class="anchor" id="line-729"></span><span class="anchor" id="line-730"></span><span class="anchor" id="line-731"></span><span class="anchor" id="line-732"></span><span class="anchor" id="line-733"></span><span class="anchor" id="line-734"></span><span class="anchor" id="line-735"></span><span class="anchor" id="line-736"></span><span class="anchor" id="line-737"></span><span class="anchor" id="line-738"></span><span class="anchor" id="line-739"></span><span class="anchor" id="line-740"></span><span class="anchor" id="line-741"></span><span class="anchor" id="line-742"></span><span class="anchor" id="line-743"></span><span class="anchor" id="line-744"></span><span class="anchor" id="line-745"></span><span class="anchor" id="line-746"></span><span class="anchor" id="line-747"></span><span class="anchor" id="line-748"></span><span class="anchor" id="line-749"></span><span class="anchor" id="line-750"></span><span class="anchor" id="line-751"></span><span class="anchor" id="line-752"></span><span class="anchor" id="line-753"></span><span class="anchor" id="line-754"></span><span class="anchor" id="line-755"></span><span class="anchor" id="line-756"></span><span class="anchor" id="line-757"></span><span class="anchor" id="line-758"></span><span class="anchor" id="line-759"></span><span class="anchor" id="line-760"></span><span class="anchor" id="line-761"></span><span class="anchor" id="line-762"></span><span class="anchor" id="line-763"></span><span class="anchor" id="line-764"></span><span class="anchor" id="line-765"></span><span class="anchor" id="line-766"></span><span class="anchor" id="line-767"></span><span class="anchor" id="line-768"></span><span class="anchor" id="line-769"></span><span class="anchor" id="line-770"></span><span class="anchor" id="line-771"></span><span class="anchor" id="line-772"></span><span class="anchor" id="line-773"></span><span class="anchor" id="line-774"></span><span class="anchor" id="line-775"></span><span class="anchor" id="line-776"></span><span class="anchor" id="line-777"></span><span class="anchor" id="line-778"></span><span class="anchor" id="line-779"></span><span class="anchor" id="line-780"></span><span class="anchor" id="line-781"></span><span class="anchor" id="line-782"></span><span class="anchor" id="line-783"></span><span class="anchor" id="line-784"></span><span class="anchor" id="line-785"></span><span class="anchor" id="line-786"></span><span class="anchor" id="line-787"></span><span class="anchor" id="line-788"></span><span class="anchor" id="line-789"></span><span class="anchor" id="line-790"></span><span class="anchor" id="line-791"></span><span class="anchor" id="line-792"></span><span class="anchor" id="line-793"></span><span class="anchor" id="line-794"></span><span class="anchor" id="line-795"></span><span class="anchor" id="line-796"></span><span class="anchor" id="line-797"></span><span class="anchor" id="line-798"></span><span class="anchor" id="line-799"></span><span class="anchor" id="line-800"></span><span class="anchor" id="line-801"></span><span class="anchor" id="line-802"></span><pre><span class="anchor" id="line-1-51"></span>#!/bin/bash
<span class="anchor" id="line-2-24"></span>#!/bin/bash
<span class="anchor" id="line-3-18"></span># print-to-pdf. A script to produce searchable PDFs.
<span class="anchor" id="line-4-13"></span>
<span class="anchor" id="line-5-13"></span># Determine the MIME media type of the file to be printed.
<span class="anchor" id="line-6-13"></span>MIMETYPE=$(file --mime-type -b &quot;$TEADATAFILE&quot;)
<span class="anchor" id="line-7-13"></span>
<span class="anchor" id="line-8-13"></span># Directory for the output file.
<span class="anchor" id="line-9-13"></span>DIR=&quot;/home/$TEAUSERNAME/PDF/&quot;
<span class="anchor" id="line-10-13"></span>
<span class="anchor" id="line-11-9"></span>CF1=cupsfilter
<span class="anchor" id="line-12-8"></span>CF2=&quot;cupsfilter -m application/vnd.cups-pdf -o&quot;
<span class="anchor" id="line-13-8"></span>TU=&quot;$TEAUSERNAME&quot;
<span class="anchor" id="line-14-8"></span>TD=&quot;$TEADATAFILE&quot;
<span class="anchor" id="line-15-7"></span>
<span class="anchor" id="line-16-7"></span># Get any page-ranges. Useful for jobs submitted with lp but not for
<span class="anchor" id="line-17-7"></span># jobs from most GTK/QT apps. The latter pre-process jobs to sort out
<span class="anchor" id="line-18-7"></span># the pages to be printed and do not send &quot;-o pages-ranges&quot; to pdftopdf.
<span class="anchor" id="line-19-7"></span>TO=$(echo &quot;$TEAOPTIONS&quot; | grep -o 'page-ranges[^ [:space:]]\+')
<span class="anchor" id="line-20-7"></span>
<span class="anchor" id="line-21-7"></span># $TEATITLE might be file:///etc/services.
<span class="anchor" id="line-22-7"></span>TT=$(basename &quot;$TEATITLE&quot;)
<span class="anchor" id="line-23-6"></span>
<span class="anchor" id="line-24-4"></span># Create directory for PDFs if it does not exist.
<span class="anchor" id="line-25-3"></span>if [ ! -d &quot;$DIR&quot; ] ; then
<span class="anchor" id="line-26-1"></span>   mkdir &quot;$DIR&quot;
<span class="anchor" id="line-27-1"></span>   chown &quot;$TU&quot;:&quot;$TU&quot; &quot;$DIR&quot;
<span class="anchor" id="line-28-1"></span>fi
<span class="anchor" id="line-29-1"></span>
<span class="anchor" id="line-30-1"></span># Put a PDF in $DIR. Make those produced from text files searchable with
<span class="anchor" id="line-31-1"></span># pdftocairo.
<span class="anchor" id="line-32-1"></span>transfer () {
<span class="anchor" id="line-33-1"></span>if [ ! -z &quot;$TO&quot; ] ; then
<span class="anchor" id="line-34-1"></span>   PAGES=$(echo $TO | cut -d&quot;=&quot; -f2)
<span class="anchor" id="line-35-1"></span>   PDF=&quot;$(echo $PDF | cut -d&quot;.&quot; -f1)_(pages_numbers_$PAGES).pdf&quot;
<span class="anchor" id="line-36-1"></span>      case &quot;$MIMETYPE&quot; in
<span class="anchor" id="line-37-1"></span>              application/pdf) $CF2 &quot;$TO&quot; &quot;$TD&quot; &gt; &quot;$DIR/$PDF&quot;                    ;;
<span class="anchor" id="line-38-1"></span>                   text/plain) $CF2 &quot;$TO&quot; &quot;$TD&quot; | pdftocairo -pdf - $DIR/$PDF    ;;
<span class="anchor" id="line-39-1"></span>       application/postscript) $CF2 &quot;$TO&quot; &quot;$TD&quot; &gt; &quot;$DIR/$PDF&quot;
<span class="anchor" id="line-40-1"></span>      esac
<span class="anchor" id="line-41-1"></span>else
<span class="anchor" id="line-42-1"></span>      case &quot;$MIMETYPE&quot; in
<span class="anchor" id="line-43"></span>              application/pdf) $CF1 &quot;$TD&quot; &gt; &quot;$DIR/$PDF&quot;                    ;;
<span class="anchor" id="line-44"></span>                   text/plain) $CF1 &quot;$TD&quot; | pdftocairo -pdf - $DIR/$PDF    ;;
<span class="anchor" id="line-45"></span>       application/postscript) $CF1 &quot;$TD&quot; &gt; &quot;$DIR/$PDF&quot;
<span class="anchor" id="line-46"></span>      esac
<span class="anchor" id="line-47"></span>fi
<span class="anchor" id="line-48"></span>chown &quot;$TU&quot;:&quot;$TU&quot; &quot;$DIR/$PDF&quot;
<span class="anchor" id="line-49"></span>}
<span class="anchor" id="line-50"></span>
<span class="anchor" id="line-51"></span># Check existence of a .pdf extension. Provide one if necessary. Replace
<span class="anchor" id="line-52"></span># a space with a &quot;_&quot;. Remove last &quot;_&quot; in a filename.
<span class="anchor" id="line-53"></span>print_pdf () {
<span class="anchor" id="line-54"></span>if [ ${TT: -4} == &quot;.pdf&quot; ] ; then
<span class="anchor" id="line-55"></span>   PDF=$(echo $TT | tr [:space:] '_' | sed 's/.$//')
<span class="anchor" id="line-56"></span>else
<span class="anchor" id="line-57"></span>   PDF=$(echo $TT | tr [:space:] '_' | sed 's/.$//').pdf
<span class="anchor" id="line-58"></span>fi
<span class="anchor" id="line-59"></span>transfer
<span class="anchor" id="line-60"></span>}
<span class="anchor" id="line-61"></span>
<span class="anchor" id="line-62"></span># Replace a space with a &quot;_&quot;. Remove last &quot;_&quot; and .txt in a filename.
<span class="anchor" id="line-63"></span>print_txt () {
<span class="anchor" id="line-64"></span>if [ ${TT: -4} == &quot;.txt&quot; ] ; then
<span class="anchor" id="line-65"></span>   PDF=$(echo $TT | tr [:space:] '_' | sed 's/.....$//').pdf
<span class="anchor" id="line-66"></span>else
<span class="anchor" id="line-67"></span>   PDF=$(echo $TT | tr [:space:] '_' | sed 's/.$//').pdf
<span class="anchor" id="line-68"></span>fi
<span class="anchor" id="line-69"></span>transfer
<span class="anchor" id="line-70"></span>}
<span class="anchor" id="line-71"></span>
<span class="anchor" id="line-72"></span># Replace a space with a &quot;_&quot;. Remove last &quot;_&quot; and .ps in a filename.
<span class="anchor" id="line-73"></span>print_ps () {
<span class="anchor" id="line-74"></span>if [ ${TT: -3} == &quot;.ps&quot; ] ; then
<span class="anchor" id="line-75"></span>   PDF=$(echo $TT | tr [:space:] '_' | sed 's/....$//').pdf
<span class="anchor" id="line-76"></span>else
<span class="anchor" id="line-77"></span>   PDF=$(echo $TT | tr [:space:] '_' | sed 's/.$//').pdf
<span class="anchor" id="line-78"></span>fi
<span class="anchor" id="line-79"></span>transfer
<span class="anchor" id="line-80"></span>}
<span class="anchor" id="line-81"></span>
<span class="anchor" id="line-82"></span>case &quot;$MIMETYPE&quot; in
<span class="anchor" id="line-83"></span>          application/pdf) print_pdf    ;;
<span class="anchor" id="line-84"></span>               text/plain) print_txt    ;;
<span class="anchor" id="line-85"></span>   application/postscript) print_ps
<span class="anchor" id="line-86"></span>esac</pre><span class="anchor" id="line-803"></span><span class="anchor" id="line-804"></span><p class="line874">All three file types avoid doing psftops and pdftops conversions (as done by cups-pdf) in the final stages of the filtering chain. Apart from PDFs of decent quality being produced there will be some decrease in processing time.  <span class="anchor" id="line-805"></span><span class="anchor" id="line-806"></span><ul><li>A PDF is passed through the system untouched. If it was searchable before, it will be searchable afterwards. <span class="anchor" id="line-807"></span></li><li><p class="line862">A PostScript file is processed by the pstopdf filter of cups-filters. This produces searchable output. <span class="anchor" id="line-808"></span></li><li>A text file is processed by the texttopdf filter of cups-filters. This does not produce a searchable PDF but post-processing with pdftocairo does. <span class="anchor" id="line-809"></span><span class="anchor" id="line-810"></span></li></ul><p class="line874">The print queue to set up: <span class="anchor" id="line-811"></span><span class="anchor" id="line-812"></span><p class="line867"><span class="anchor" id="line-813"></span><span class="anchor" id="line-814"></span><pre><span class="anchor" id="line-1-52"></span>lpadmin -p PrinttoPDF -v tea4cups:// -E -m raw</pre><span class="anchor" id="line-815"></span><span class="anchor" id="line-816"></span><p class="line874">The prehook to use: <span class="anchor" id="line-817"></span><span class="anchor" id="line-818"></span><p class="line867"><span class="anchor" id="line-819"></span><span class="anchor" id="line-820"></span><pre><span class="anchor" id="line-1-53"></span>prehook_pdf : /usr/local/bin/&lt;print-to-pdf&gt;</pre><span class="anchor" id="line-821"></span><span class="anchor" id="line-822"></span><p class="line867"><span class="anchor" id="pdfa1"></span> <span class="anchor" id="line-823"></span>
<h3 id="Creating_a_PDF.2FA_Document_with_unoconv">Creating a PDF/A Document with unoconv</h3>
<span class="anchor" id="line-824"></span><span class="anchor" id="line-825"></span><p class="line874">Some individuals and organisations want to have PDFs they produce or <span class="anchor" id="line-826"></span>acquire accessible many, many years from now and to this end there is an <span class="anchor" id="line-827"></span>ISO specification treating long term archiving of PDF documents. The <span class="anchor" id="line-828"></span>technical aspects are described at the <a class="http" href="http://www.pdfa.org/2011/08/pdfa-%E2%80%93-a-look-at-the-technical-side/">PDF Association</a> and at <a class="http" href="http://www.pdflib.com/knowledge-base/pdfa/">PDFlib GmbH</a>. <span class="anchor" id="line-829"></span><span class="anchor" id="line-830"></span><p class="line862">The only software in Debian which appears to support conversion of non-PDF and non-Postscript documents to PDF/A is Libreoffice. It is designed to produce <a class="https" href="https://wiki.openoffice.org/wiki/API/Tutorials/PDF_export#General_properties">PDF/A-1a compliant files</a>. <span class="anchor" id="line-831"></span><span class="anchor" id="line-832"></span><p class="line862">As in the section <a href="/Tea4CUPS#Printing_Microsoft_Documents">Printing Microsoft documents</a> have unoconv listening in the background and set up a <a href="/Tea4CUPS#Capturing_an_Input_File">virtual raw queue</a> with lpadmin or the web interface of CUPS. Create a doc-pdfa directory in /usr/local/share. <span class="anchor" id="line-833"></span><span class="anchor" id="line-834"></span><p class="line874">A very simple script would be <span class="anchor" id="line-835"></span><span class="anchor" id="line-836"></span><p class="line867"><span class="anchor" id="line-837"></span><span class="anchor" id="line-838"></span><span class="anchor" id="line-839"></span><span class="anchor" id="line-840"></span><span class="anchor" id="line-841"></span><span class="anchor" id="line-842"></span><span class="anchor" id="line-843"></span><pre><span class="anchor" id="line-1-54"></span>  #!/bin/bash
<span class="anchor" id="line-2-25"></span>  #!/bin/bash
<span class="anchor" id="line-3-19"></span>  
<span class="anchor" id="line-4-14"></span>  OUTPDF=/usr/local/share/doc-pdfa/$TEATITLE.pdf
<span class="anchor" id="line-5-14"></span>  unoconv -f pdf -eSelectPdfVersion=1 -o $OUTPDF $1
<span class="anchor" id="line-6-14"></span>  chmod 444 $OUTPDF</pre><span class="anchor" id="line-844"></span><span class="anchor" id="line-845"></span><p class="line874">which is called from <span class="anchor" id="line-846"></span><span class="anchor" id="line-847"></span><p class="line867"><span class="anchor" id="line-848"></span><span class="anchor" id="line-849"></span><pre><span class="anchor" id="line-1-55"></span>  prehook_pdfa_unoconv : /usr/local/bin/pdfa-unoconv $TEADATAFILE</pre><span class="anchor" id="line-850"></span><span class="anchor" id="line-851"></span><p class="line867"><span class="anchor" id="pdfa2"></span> <span class="anchor" id="line-852"></span>
<h3 id="Creating_a_PDF.2FA_Document_with_Ghostscript">Creating a PDF/A Document with Ghostscript</h3>
<span class="anchor" id="line-853"></span><span class="anchor" id="line-854"></span><p class="line862">PDF and PostScript files types are not candidates for <a href="/Tea4CUPS#Creating_a_PDF.2FA_document_with_unoconv">conversion with unoconv</a> but Ghostscript can produce PDF/A-1b and PDF/A-2b outputs as documented on the <a class="http" href="http://ghostscript.com/doc/current/Ps2pdf.htm#PDFA">PostScript-to-PDF converter</a> web page. The <a class="http" href="http://ghostscript.com/FAQ.html">Ghostscript FAQ</a> explains why PDF/A-1a production is not supported. <span class="anchor" id="line-855"></span><span class="anchor" id="line-856"></span><p class="line862">Following the <a class="http" href="http://bugs.ghostscript.com/show_bug.cgi?id=691448">advice in this bug report</a> the system's PDFA_def.ps is copied to /usr/local/share/ghostscript and (if Debian 8 is being used) the line <span class="anchor" id="line-857"></span><span class="anchor" id="line-858"></span><p class="line867"><span class="anchor" id="line-859"></span><span class="anchor" id="line-860"></span><pre><span class="anchor" id="line-1-56"></span>  /ICCProfile (ISO Coated sb.icc)   % Customize.</pre><span class="anchor" id="line-861"></span><span class="anchor" id="line-862"></span><p class="line874">is altered to something which suits, such as <span class="anchor" id="line-863"></span><span class="anchor" id="line-864"></span><p class="line867"><span class="anchor" id="line-865"></span><span class="anchor" id="line-866"></span><pre><span class="anchor" id="line-1-57"></span>  /ICCProfile (/usr/share/color/icc/ghostscript/srgb.icc)   % Customize.</pre><span class="anchor" id="line-867"></span><span class="anchor" id="line-868"></span><p class="line862">The ghostscript directory will have to be created and you are advised to use the full path to the *.icc file even if not on Jessie. You might also want to <a class="interwiki" href="https://bugs.debian.org/801395" title="DebianBug">read this Debian bug report</a>. <span class="anchor" id="line-869"></span><span class="anchor" id="line-870"></span><p class="line862">The Tea4CUPS queue setup is the same <a href="/Tea4CUPS#Creating_a_PDF.2FA_document_with_unoconv">as with unoconv</a> and a basic script for converting a PDF to PDF/A-1b could look like this: <span class="anchor" id="line-871"></span><span class="anchor" id="line-872"></span><p class="line867"><span class="anchor" id="line-873"></span><span class="anchor" id="line-874"></span><span class="anchor" id="line-875"></span><span class="anchor" id="line-876"></span><span class="anchor" id="line-877"></span><span class="anchor" id="line-878"></span><span class="anchor" id="line-879"></span><span class="anchor" id="line-880"></span><span class="anchor" id="line-881"></span><span class="anchor" id="line-882"></span><span class="anchor" id="line-883"></span><span class="anchor" id="line-884"></span><span class="anchor" id="line-885"></span><span class="anchor" id="line-886"></span><span class="anchor" id="line-887"></span><span class="anchor" id="line-888"></span><span class="anchor" id="line-889"></span><pre><span class="anchor" id="line-1-58"></span>  #!/bin/bash
<span class="anchor" id="line-2-26"></span>  #!/bin/bash
<span class="anchor" id="line-3-20"></span>
<span class="anchor" id="line-4-15"></span>  # Remove pdf extension (.pdf) from the input file name.
<span class="anchor" id="line-5-15"></span>  BN=$(basename $TEATITLE .pdf)
<span class="anchor" id="line-6-15"></span>  # Replace extension when output file is produced.
<span class="anchor" id="line-7-14"></span>  OUTPDF=/usr/local/share/doc-pdfa/$BN.pdf
<span class="anchor" id="line-8-14"></span>
<span class="anchor" id="line-9-14"></span>  gs -dPDFA=1  -dBATCH -dNOPAUSE  -sDEVICE=pdfwrite  \
<span class="anchor" id="line-10-14"></span>     -sColorConversionStrategy=/RGB                  \
<span class="anchor" id="line-11-10"></span>     -dPDFACompatibilityPolicy=1                     \
<span class="anchor" id="line-12-9"></span>     -sOutputFile=$OUTPDF                            \
<span class="anchor" id="line-13-9"></span>      /usr/local/share/ghostscript/PDFA_def.ps       \
<span class="anchor" id="line-14-9"></span>      $1
<span class="anchor" id="line-15-8"></span>
<span class="anchor" id="line-16-8"></span>  chmod 444 $OUTPDF</pre><span class="anchor" id="line-890"></span><span class="anchor" id="line-891"></span><p class="line874">The prehook is <span class="anchor" id="line-892"></span><span class="anchor" id="line-893"></span><p class="line867"><span class="anchor" id="line-894"></span><span class="anchor" id="line-895"></span><pre><span class="anchor" id="line-1-59"></span>  prehook_pdfa_gs : /usr/local/bin/pdfa-gs $TEADATAFILE</pre><span class="anchor" id="line-896"></span><span class="anchor" id="line-897"></span><p class="line874">PDF files may contain transparent objects and layers but transparency is not permitted in the PDF/A-1 specification. Ghostscript deals with this by rendering such portions of the PDF to images.  &quot;Text&quot; in these regions is no longer text after this and is not searchable or extractable. <span class="anchor" id="line-898"></span><span class="anchor" id="line-899"></span><p class="line874">If a searchable PDF/A-1a is a requirement you can add -dNOTRANSPARENCY to the gs command line, but be aware this could lead to altering the PDF for screen display or printing. PDF/A-2 handles transparency, so an alternative approach is replacing -dPDFA=1 with -dPDFA=2 on the gs command line. <span class="anchor" id="line-900"></span><span class="anchor" id="line-901"></span><p class="line867"><span class="anchor" id="line-902"></span><span class="anchor" id="line-903"></span><span class="anchor" id="line-904"></span><span class="anchor" id="line-905"></span><span class="anchor" id="line-906"></span><span class="anchor" id="line-907"></span><span class="anchor" id="line-908"></span><span class="anchor" id="line-909"></span><span class="anchor" id="line-910"></span><div class="tip"><span class="anchor" id="line-1-1"></span><p class="line867"><strong>Tip</strong> <span class="anchor" id="line-2-1"></span><span class="anchor" id="line-3-1"></span><p class="line874">It is worthwhile testing PDFs for transparency prior to processing because the conversion of a whole page to an image can take a long time and involve much swapping out to disk. <span class="anchor" id="line-4-1"></span><span class="anchor" id="line-5-1"></span><p class="line862">Obtain pdf_info.ps from the toolbin directory in the <a class="http" href="http://http.debian.net/debian/pool/main/g/ghostscript/ghostscript_9.06~dfsg.orig.tar.gz">Ghostscript source package</a> and run <span class="anchor" id="line-6-1"></span><span class="anchor" id="line-7-1"></span><ul><li style="list-style-type:none">gs -dNODISPLAY -q -sFile=your.pdf pdf_info.ps </li></ul></div><span class="anchor" id="line-911"></span><span class="anchor" id="line-912"></span><p class="line867"><span class="anchor" id="accounting1"></span> <span class="anchor" id="line-913"></span>
<h3 id="Printer_Accounting">Printer Accounting</h3>
<span class="anchor" id="line-914"></span><span class="anchor" id="line-915"></span><p class="line874">The accounting schemes which CUPS supports are outlined at <span class="anchor" id="line-916"></span><a class="https" href="https://www.cups.org/documentation.php/doc-1.7/accounting.html">the CUPS website</a> and on <span class="anchor" id="line-917"></span><a class="http" href="http://localhost:631/help/accounting.html">on a machine with cups installed</a>. Some of the problems associated with obtaining accurate information with software     <span class="anchor" id="line-918"></span>accounting are discussed on these <a class="https" href="https://en.opensuse.org/SDB:Printer_Accounting">openSUSE</a> and <a class="https" href="https://community.kde.org/Printing/CUPS/FAQ">KDE</a> pages. <span class="anchor" id="line-919"></span><span class="anchor" id="line-920"></span><p class="line862">Whatever the pitfalls of software approaches to counting printed pages it is suggested you take a look at <a class="interwiki" href="https://manpages.debian.org/man/pkpgcounter" title="DebianMan">pkpgcounter</a>. It is easy enough to use as a prehook and can provide information for a raw queue. $TEATITLE may contain spaces; they will need removing. <span class="anchor" id="line-921"></span><span class="anchor" id="line-922"></span><p class="line867"><span class="anchor" id="line-923"></span><span class="anchor" id="line-924"></span><pre><span class="anchor" id="line-1-60"></span>  prehook _accounting : echo $TEAUSERNAME $TEATITLE `pkpgcounter $TEADATAFILE` $TEACOPIES &gt;&gt; /var/log/cups/printaccounting.log</pre><span class="anchor" id="line-925"></span><span class="anchor" id="line-926"></span><p class="line874">pkpgcounter calculates the number of pages to print a given document of a recognised file type. Multipling by the number of copies gives the total number of pages used. $TEACOPIES is the number of copies recorded by CUPS in argv[4] of the error_log; that is, the number of copies asked for when the job is submitted to cups. How this is managed depends on CUPS and the printer driver. The CUPS filters could decide to produce a single copy but instruct the CUPS backend to send that copy several times in a row. <span class="anchor" id="line-927"></span><span class="anchor" id="line-928"></span><p class="line874">It might be useful to know that the -d option to pkpgcounter displays the file format of a document it is given to examine. <span class="anchor" id="line-929"></span><span class="anchor" id="line-930"></span><p class="line874">A sample printaccounting.log: <span class="anchor" id="line-931"></span><span class="anchor" id="line-932"></span><p class="line867"><span class="anchor" id="line-933"></span><span class="anchor" id="line-934"></span><span class="anchor" id="line-935"></span><span class="anchor" id="line-936"></span><span class="anchor" id="line-937"></span><span class="anchor" id="line-938"></span><pre><span class="anchor" id="line-1-61"></span>  brian nsswitch.conf 1 1
<span class="anchor" id="line-2-27"></span>  brian PlanetDebian 104 1
<span class="anchor" id="line-3-21"></span>  brian linux-Howtoextractthefilenamewithouttheextensionfromafullpath?-SuperUser 2 1
<span class="anchor" id="line-4-16"></span>  brian https://www.debian.org/releases/stable/amd64/install.txt.en 94 5
<span class="anchor" id="line-5-16"></span>  brian services 4 3</pre><span class="anchor" id="line-939"></span><span class="anchor" id="line-940"></span><p class="line874">And a way of calculating pages printed: <span class="anchor" id="line-941"></span><span class="anchor" id="line-942"></span><p class="line867"><span class="anchor" id="line-943"></span><span class="anchor" id="line-944"></span><pre><span class="anchor" id="line-1-62"></span>  awk '{ total+=$3*$4 }  END { print total }' /var/log/cups/printaccounting.log</pre><span class="anchor" id="line-945"></span><span class="anchor" id="line-946"></span><p class="line867"><span class="anchor" id="accounting2"></span> <span class="anchor" id="line-947"></span>
<h3 id="Printer_Accounting_and_the_Page_Log">Printer Accounting and the Page Log</h3>
<span class="anchor" id="line-948"></span><span class="anchor" id="line-949"></span><p class="line862">The page_log file in <em>/var/log/cups/</em> lists each page that is sent to a print queue and can be used as the basis for printer accounting. There is a proviso though (which is mentioned in the documentation) - drivers <a class="http" href="http://www.cups.org/pipermail/cups/2009-April/018592.html">must provide</a> page accounting information. <span class="anchor" id="line-950"></span><span class="anchor" id="line-951"></span><p class="line867"><span class="anchor" id="line-952"></span><span class="anchor" id="line-953"></span><span class="anchor" id="line-954"></span><span class="anchor" id="line-955"></span><span class="anchor" id="line-956"></span><pre><span class="anchor" id="line-1-63"></span>Except for PostScript printers with no filters, page_log depends on
<span class="anchor" id="line-2-28"></span>the driver generating PAGE: messages for each page it produces.  If
<span class="anchor" id="line-3-22"></span>the driver doesn't generate PAGE: messages, you don't get a page_log
<span class="anchor" id="line-4-17"></span>file.</pre><span class="anchor" id="line-957"></span><span class="anchor" id="line-958"></span><p class="line874">Let us take the example of an HP M401dne printer; it uses a PPD file from the printer-driver-postscript-hp package and the PPD has the line <span class="anchor" id="line-959"></span><span class="anchor" id="line-960"></span><p class="line867"><span class="anchor" id="line-961"></span><span class="anchor" id="line-962"></span><pre><span class="anchor" id="line-1-64"></span>  *cupsFilter: &quot;application/vnd.cups-postscript 0 hpps</pre><span class="anchor" id="line-963"></span><span class="anchor" id="line-964"></span><p class="line874">in it. <span class="anchor" id="line-965"></span><span class="anchor" id="line-966"></span><p class="line874">For a PDF submitted to a queue using this PPD the filter chain would be <span class="anchor" id="line-967"></span><span class="anchor" id="line-968"></span><p class="line867"><span class="anchor" id="line-969"></span><span class="anchor" id="line-970"></span><pre><span class="anchor" id="line-1-65"></span>  PDF in --&gt; pdftopdf --&gt; pdftops --&gt; hpps --&gt; PostScript out</pre><span class="anchor" id="line-971"></span><span class="anchor" id="line-972"></span><p class="line862">and pdftops starts the pstops filter. pstops does do page accounting but unfortunately <a class="interwiki" href="https://bugs.launchpad.net/bugs/1442684" title="UbuntuBug">hpps does not</a> and, because it is the final filter in the chain, the page_log file is empty. Fortunately, Tea4CUPS can help out. <span class="anchor" id="line-973"></span><span class="anchor" id="line-974"></span><p class="line874">Set up a queue for the M401 in the usual way: <span class="anchor" id="line-975"></span><span class="anchor" id="line-976"></span><p class="line867"><span class="anchor" id="line-977"></span><span class="anchor" id="line-978"></span><pre><span class="anchor" id="line-1-66"></span>  lpadmin -realq -v &lt;DEVICE_URI&gt; -E -m &lt;401dne_PPD&gt;</pre><span class="anchor" id="line-979"></span><span class="anchor" id="line-980"></span><p class="line874">Copy 401dne_PPD, edit to remove the *cupsFilter line from it and set up a second <span class="anchor" id="line-981"></span>queue: <span class="anchor" id="line-982"></span><span class="anchor" id="line-983"></span><p class="line867"><span class="anchor" id="line-984"></span><span class="anchor" id="line-985"></span><pre><span class="anchor" id="line-1-67"></span>  lpadmin -p pagelogq -v file:/dev/null -E -m &lt;401dne_PPD_without_*cupsFilter&gt;</pre><span class="anchor" id="line-986"></span><span class="anchor" id="line-987"></span><p class="line874">Set up a virtual raw queue with the tea4cups backend: <span class="anchor" id="line-988"></span><span class="anchor" id="line-989"></span><p class="line867"><span class="anchor" id="line-990"></span><span class="anchor" id="line-991"></span><pre><span class="anchor" id="line-1-68"></span>  lpadmin -p m401 -v tea4cups:// -E -m raw</pre><span class="anchor" id="line-992"></span><span class="anchor" id="line-993"></span><p class="line874">Now have two hooks in tea4cups.conf; one to send the job to the printer and one to write to page_log when pdftops is the final filter in the filter chain. <span class="anchor" id="line-994"></span><span class="anchor" id="line-995"></span><p class="line867"><span class="anchor" id="line-996"></span><span class="anchor" id="line-997"></span><span class="anchor" id="line-998"></span><pre><span class="anchor" id="line-1-69"></span>  prehook_pagelog : lp -d pagelogq -U &quot;$TEAUSERNAME&quot; -t &quot;$TEATITLE&quot; $TEADATAFILE&quot;
<span class="anchor" id="line-2-29"></span>  prehook_print : lp -d realq &quot;$TEADATAFILE&quot;</pre><span class="anchor" id="line-999"></span><span class="anchor" id="line-1000"></span><p class="line867"><span class="anchor" id="line-1001"></span><span class="anchor" id="line-1002"></span><div class="important"><span class="anchor" id="line-1-2"></span><p class="line862">CUPS 2.0b1 and later has page_log files disabled by default. Enabling them is a matter of providing a value for <em>PageLogFormat</em>, which is present in cups.conf but with an empty string. </div><span class="anchor" id="line-1003"></span><span class="anchor" id="line-1004"></span><p class="line867"><span class="anchor" id="reshare"></span> <span class="anchor" id="line-1005"></span>
<h3 id="Resharing_a_Raw_Print_Queue">Resharing a Raw Print Queue</h3>
<span class="anchor" id="line-1006"></span><span class="anchor" id="line-1007"></span><p class="line874">A printer is connected by USB to a server running cupsd. Because of resource constraints and other considerations a decision is taken not to have avahi-daemon on the server. This means the print queue set up with <span class="anchor" id="line-1008"></span><span class="anchor" id="line-1009"></span><p class="line867"><span class="anchor" id="line-1010"></span><span class="anchor" id="line-1011"></span><pre><span class="anchor" id="line-1-70"></span>  lpadmin -p printq -v usb://.... -E -o printer-is-shared -m &lt;PPD&gt;</pre><span class="anchor" id="line-1012"></span><span class="anchor" id="line-1013"></span><p class="line874">is not advertised. On another machine a queue pointing to printq could be used to access the printer: <span class="anchor" id="line-1014"></span><span class="anchor" id="line-1015"></span><p class="line867"><span class="anchor" id="line-1016"></span><span class="anchor" id="line-1017"></span><pre><span class="anchor" id="line-1-71"></span>  lpadmin -p anotherq -v ipp://&lt;IP_of_server&gt;/printers/printq -E -m raw</pre><span class="anchor" id="line-1018"></span><span class="anchor" id="line-1019"></span><p class="line874">anotherq is a raw queue so any job sent from there to printq doesn't get <span class="anchor" id="line-1020"></span>processed until it reaches the server. <span class="anchor" id="line-1021"></span><span class="anchor" id="line-1022"></span><p class="line862">The second machine does have avahi-daemon so it might look reasonable to broadcast the existence of anotherq by adding <em>-o printer-is-shared</em> to the previous lpadmin command. Unfortunately, this does not work and is very unlikely to work with any future CUPS.  Explanations and discussion are in <a class="https" href="https://www.cups.org/str.php?L4738">STR#4738</a> and <a class="https" href="https://www.cups.org/str.php?L4766">STR#4766</a>. <span class="anchor" id="line-1023"></span><span class="anchor" id="line-1024"></span><p class="line874">But what we can do is set up a Tea4CUPS virtual print queue with <span class="anchor" id="line-1025"></span><span class="anchor" id="line-1026"></span><p class="line867"><span class="anchor" id="line-1027"></span><span class="anchor" id="line-1028"></span><pre><span class="anchor" id="line-1-72"></span>  lpadmin -p yetanotherq -v tea4cups:// -E -o printer-is-shared -m raw</pre><span class="anchor" id="line-1029"></span><span class="anchor" id="line-1030"></span><p class="line874">and have a pre-hook directing the print job to anotherq: <span class="anchor" id="line-1031"></span><span class="anchor" id="line-1032"></span><p class="line867"><span class="anchor" id="line-1033"></span><span class="anchor" id="line-1034"></span><pre><span class="anchor" id="line-1-73"></span>  prehook_reshare : lp -d anotherq -o &quot;$TEAOPTIONS&quot; &quot;$TEADATAFILE&quot;</pre><span class="anchor" id="line-1035"></span><span class="anchor" id="line-1036"></span><p class="line874">There is no restriction made by CUPS on the virtual queue being shared. <span class="anchor" id="line-1037"></span><span class="anchor" id="line-1038"></span><p class="line867"><span class="anchor" id="line-1039"></span><span class="anchor" id="line-1040"></span><div class="important"><span class="anchor" id="line-1-3"></span><p class="line862">Versions of cups-browsed less than 1.8.2 will not create a local queue pointing to a remote yetanother queue, so that queue will not be visible to command line programs or non-GTK applications on the client machine. Please see <a class="interwiki" href="https://bugs.debian.org/814020" title="DebianBug">bug #814020</a>. </div><span class="anchor" id="line-1041"></span><span class="anchor" id="line-1042"></span><p class="line867"><span class="anchor" id="custom"></span> <span class="anchor" id="line-1043"></span>
<h3 id="A_Customised_Printing_Dialog">A Customised Printing Dialog</h3>
<span class="anchor" id="line-1044"></span><span class="anchor" id="line-1045"></span><p class="line874">Many people regularly use a restricted set of printing options to send a job to a print queue. For example, they might always want duplex printing at draft quality as the default method when using a particular colour laser printer and only switch to a better quality when the printout is work-related. Or again, a user is only interested in printing images at photo quality on glossy 4x6 paper with the choice of borderless or not. It can be a chore to continually have to decide on and change options when printing from applications or the command line when there is a clearly defined task. <span class="anchor" id="line-1046"></span><span class="anchor" id="line-1047"></span><p class="line862">Setting up a different <a href="/PrintQueuesCUPS">print queue</a> for each task is an option which could be taken, as is using <a class="interwiki" href="https://manpages.debian.org/man/lpoptions" title="DebianMan">lpoptions</a> with an instance. This section presents an alternative technique using Tea4CUPS and a script. The script below, <em>print-dialog</em>, provides a description of the task to be undertaken and avoids any repetitive changing of printing options. The idea is to have a dialog which does not require a user to have to remember queue names or think too deeply about printing options or provide extensive input. The script can easily be tailored to the needs of the user. It is presented here in the context of an application which uses the GTK (<a class="interwiki" href="https://packages.debian.org/firefox" title="DebPkg">firefox</a>, <a class="interwiki" href="https://packages.debian.org/evince" title="DebPkg">evince</a> etc) and QT (<a class="interwiki" href="https://packages.debian.org/okular" title="DebPkg">okular</a>, <a class="interwiki" href="https://packages.debian.org/qpdfview" title="DebPkg">qpdfview</a> etc) print dialogs or when printing from the command line in an <a class="interwiki" href="https://manpages.debian.org/man/xterm" title="DebianMan">xterm</a> (or something similar) with <a class="interwiki" href="https://manpages.debian.org/man/lp" title="DebianMan">lp</a>. <span class="anchor" id="line-1048"></span><span class="anchor" id="line-1049"></span><p class="line867"><span class="anchor" id="line-1050"></span><span class="anchor" id="line-1051"></span><span class="anchor" id="line-1052"></span><span class="anchor" id="line-1053"></span><span class="anchor" id="line-1054"></span><span class="anchor" id="line-1055"></span><span class="anchor" id="line-1056"></span><span class="anchor" id="line-1057"></span><span class="anchor" id="line-1058"></span><span class="anchor" id="line-1059"></span><span class="anchor" id="line-1060"></span><span class="anchor" id="line-1061"></span><span class="anchor" id="line-1062"></span><span class="anchor" id="line-1063"></span><span class="anchor" id="line-1064"></span><span class="anchor" id="line-1065"></span><span class="anchor" id="line-1066"></span><span class="anchor" id="line-1067"></span><span class="anchor" id="line-1068"></span><span class="anchor" id="line-1069"></span><span class="anchor" id="line-1070"></span><span class="anchor" id="line-1071"></span><span class="anchor" id="line-1072"></span><span class="anchor" id="line-1073"></span><span class="anchor" id="line-1074"></span><span class="anchor" id="line-1075"></span><span class="anchor" id="line-1076"></span><span class="anchor" id="line-1077"></span><span class="anchor" id="line-1078"></span><span class="anchor" id="line-1079"></span><span class="anchor" id="line-1080"></span><span class="anchor" id="line-1081"></span><span class="anchor" id="line-1082"></span><span class="anchor" id="line-1083"></span><span class="anchor" id="line-1084"></span><span class="anchor" id="line-1085"></span><span class="anchor" id="line-1086"></span><span class="anchor" id="line-1087"></span><span class="anchor" id="line-1088"></span><span class="anchor" id="line-1089"></span><span class="anchor" id="line-1090"></span><span class="anchor" id="line-1091"></span><span class="anchor" id="line-1092"></span><span class="anchor" id="line-1093"></span><span class="anchor" id="line-1094"></span><span class="anchor" id="line-1095"></span><pre><span class="anchor" id="line-1-74"></span>#!/bin/bash
<span class="anchor" id="line-2-30"></span>
<span class="anchor" id="line-3-23"></span># print-dialog. A script to present a user with a limited set of printing options.
<span class="anchor" id="line-4-18"></span>
<span class="anchor" id="line-5-17"></span>JOB=$1
<span class="anchor" id="line-6-16"></span>
<span class="anchor" id="line-7-15"></span>msg()
<span class="anchor" id="line-8-15"></span>{
<span class="anchor" id="line-9-15"></span>dialog --msgbox &quot;Printing is in progress. Press the ENTER \
<span class="anchor" id="line-10-15"></span>key or click on OK to dismiss this notice.&quot; 8 40
<span class="anchor" id="line-11-11"></span>rm &quot;$JOB&quot;
<span class="anchor" id="line-12-10"></span>}
<span class="anchor" id="line-13-10"></span>
<span class="anchor" id="line-14-10"></span># Assumes realq is visible to lpstat on the machine being printed from.
<span class="anchor" id="line-15-9"></span># Use 'lp -h &lt;hostname_or_IP&gt; -d realq' for a non-advertised network queue.
<span class="anchor" id="line-16-9"></span># Use 'lpoptions -p realq -l' for the default PPD options of realq.
<span class="anchor" id="line-17-8"></span>printing()
<span class="anchor" id="line-18-8"></span>{
<span class="anchor" id="line-19-8"></span>case $choice in
<span class="anchor" id="line-20-8"></span>        1) lp -d realq -o 'fit-to-page Duplex=DuplexNoTumble OutputMode=Draft' &quot;$JOB&quot;
<span class="anchor" id="line-21-8"></span>           msg        ;;
<span class="anchor" id="line-22-8"></span>        2) lp -d realq -o 'fit-to-page Duplex=DuplexNoTumble OutputMode=Best' &quot;$JOB&quot;
<span class="anchor" id="line-23-7"></span>           msg        ;;
<span class="anchor" id="line-24-5"></span>        3) lp -d realq -o 'MediaType=Glossy OutputMode=Photo PageSize=Photo4x6' &quot;$JOB&quot;
<span class="anchor" id="line-25-4"></span>           msg        ;;
<span class="anchor" id="line-26-2"></span>esac
<span class="anchor" id="line-27-2"></span>}
<span class="anchor" id="line-28-2"></span>
<span class="anchor" id="line-29-2"></span>dialog --backtitle &quot;Printing selection&quot; \
<span class="anchor" id="line-30-2"></span>--radiolist &quot;Move up and down with the arrow keys or choose \
<span class="anchor" id="line-31-2"></span>1, 2 or 3 from the keyboard. Select with the SPACEBAR. Press \
<span class="anchor" id="line-32-2"></span>the ENTER key. \n\nYou can also use the mouse to \
<span class="anchor" id="line-33-2"></span>select (click on the choice) and print (click on OK).&quot; 20 85 4 \
<span class="anchor" id="line-34-2"></span>1 &quot;Print double-sided at draft quality&quot; off \
<span class="anchor" id="line-35-2"></span>2 &quot;Print double-sided at best quality&quot; off \
<span class="anchor" id="line-36-2"></span>3 &quot;Print a photo on 6x4 glossy paper with borders&quot; off 2&gt; /tmp/menuchoice.$$
<span class="anchor" id="line-37-2"></span>
<span class="anchor" id="line-38-2"></span>sel=$?
<span class="anchor" id="line-39-2"></span>choice=$(cat /tmp/menuchoice.$$)
<span class="anchor" id="line-40-2"></span>case $sel in
<span class="anchor" id="line-41-2"></span>    0) printing ; rm /tmp/menuchoice.$$ ;;
<span class="anchor" id="line-42-2"></span>    1) clear                            ;;
<span class="anchor" id="line-43-1"></span>  255)                                  ;;
<span class="anchor" id="line-44-1"></span>esac</pre><span class="anchor" id="line-1096"></span><span class="anchor" id="line-1097"></span><p class="line862">Although some adjustment might be required, a working set of prehooks with a <a href="/Tea4CUPS#capturing">virtual raw queue</a> (<em>virtq</em>) is: <span class="anchor" id="line-1098"></span><span class="anchor" id="line-1099"></span><p class="line867"><span class="anchor" id="line-1100"></span><span class="anchor" id="line-1101"></span><span class="anchor" id="line-1102"></span><span class="anchor" id="line-1103"></span><span class="anchor" id="line-1104"></span><pre><span class="anchor" id="line-1-75"></span>[virtq]
<span class="anchor" id="line-2-31"></span>prehook_print-dialog_0 : cp $TEADATAFILE /tmp/job
<span class="anchor" id="line-3-24"></span>prehook_print-dialog_1 : chown $TEAUSERNAME:$TEAUSERNAME /tmp/job
<span class="anchor" id="line-4-19"></span>prehook_print-dialog_2 : LANG=C XAUTHORITY=/home/$TEAUSERNAME/.Xauthority DISPLAY=:0 su -c &quot;xterm -geometry 100x35+0+0 -fa DejaVuSansMono -e print-dialog /tmp/job&quot; $TEAUSERNAME</pre><span class="anchor" id="line-1105"></span><span class="anchor" id="line-1106"></span><p class="line862">The third prehook ensures the xterm and the print-dialog script run as a user and not as root. Because of this the first two prehooks are needed to ensure the submitted file can be printed from a user account (which does not have access to <em>/var/spool/cups</em>). <span class="anchor" id="line-1107"></span><span class="anchor" id="line-1108"></span><ul><li><p class="line862">For a non-advertised realq this is possibly another way to <a href="/Tea4CUPS#nup1">enforce printing options</a>. <span class="anchor" id="line-1109"></span><span class="anchor" id="line-1110"></span></li><li class="gap"><p class="line862">The <a class="interwiki" href="https://manpages.debian.org/man/dialog" title="DebianMan">dialog utility</a> has GUI equivalents of <a class="interwiki" href="https://manpages.debian.org/man/yad" title="DebianMan">yad</a> and <a class="interwiki" href="https://manpages.debian.org/man/zenity" title="DebianMan">zenity</a>. These could be a more suitable fit to your needs. Bear in mind the effect any alterations to the print-dialog script have on the prehook scripts if either one of these packages is used. <span class="anchor" id="line-1111"></span><span class="anchor" id="line-1112"></span></li></ul><p class="line867">
<h3 id="Dealing_with_Duplicate_Print_Jobs">Dealing with Duplicate Print Jobs</h3>
<span class="anchor" id="line-1113"></span><span class="anchor" id="line-1114"></span><p class="line874">Users often experience that a file sent for printing comes out of the printer almost immediately. When it does not, some are given to sending the file again (and again!) under the mistaken impression that this will kick the system into action. We are not concerned here with the causes of the delay. Network problems, limitations on resources (disk space, printer memory, CPU etc) and large print jobs already in the queue or being sent can be some of the factors. What we are concerned with is the paper and ink/toner wastage when all the sent duplicate jobs eventually get printed. <span class="anchor" id="line-1115"></span><span class="anchor" id="line-1116"></span><p class="line862">With the following script all duplicates sent to the queue are deleted. No account is taken of the reason why a second job is submitted, whether it be due to impatience or oversight or it is intentional. The script relies on the md5sum ($TEAMD5SUM) being the same for each submitted duplicate job. <em>/etc/cups/tea4cups.conf</em> mentions a situation in which this might not be the case. <span class="anchor" id="line-1117"></span><span class="anchor" id="line-1118"></span><p class="line867"><span class="anchor" id="line-1119"></span><span class="anchor" id="line-1120"></span><span class="anchor" id="line-1121"></span><span class="anchor" id="line-1122"></span><span class="anchor" id="line-1123"></span><span class="anchor" id="line-1124"></span><span class="anchor" id="line-1125"></span><span class="anchor" id="line-1126"></span><span class="anchor" id="line-1127"></span><span class="anchor" id="line-1128"></span><span class="anchor" id="line-1129"></span><span class="anchor" id="line-1130"></span><span class="anchor" id="line-1131"></span><span class="anchor" id="line-1132"></span><span class="anchor" id="line-1133"></span><span class="anchor" id="line-1134"></span><span class="anchor" id="line-1135"></span><span class="anchor" id="line-1136"></span><span class="anchor" id="line-1137"></span><span class="anchor" id="line-1138"></span><pre><span class="anchor" id="line-1-76"></span>#!/bin/bash
<span class="anchor" id="line-2-32"></span>#!/bin/bash
<span class="anchor" id="line-3-25"></span># rmdup. Delete duplicate jobs.
<span class="anchor" id="line-4-20"></span>
<span class="anchor" id="line-5-18"></span>REALQ=realq
<span class="anchor" id="line-6-17"></span>MD5SUM=/tmp/MD5SUM
<span class="anchor" id="line-7-16"></span>if [ ! -e &quot;$MD5SUM&quot; ] ; then 
<span class="anchor" id="line-8-16"></span>   touch &quot;$MD5SUM&quot;
<span class="anchor" id="line-9-16"></span>fi
<span class="anchor" id="line-10-16"></span>
<span class="anchor" id="line-11-12"></span>DUP=$(grep &quot;$TEAUSERNAME&quot; &quot;$MD5SUM&quot; | cut -d&quot;:&quot; -f2 | grep -m1 &quot;$TEAMD5SUM&quot;)
<span class="anchor" id="line-12-11"></span>
<span class="anchor" id="line-13-11"></span>if [ -z &quot;$DUP&quot; ] ; then
<span class="anchor" id="line-14-11"></span>   lp -d &quot;$REALQ&quot; &quot;$TEADATAFILE&quot;
<span class="anchor" id="line-15-10"></span>   echo &quot;$TEAUSERNAME:TEAMD5SUM&quot; &gt;&gt; &quot;$MD5SUM&quot;
<span class="anchor" id="line-16-10"></span>else
<span class="anchor" id="line-17-9"></span>   rm &quot;$TEADATAFILE&quot;
<span class="anchor" id="line-18-9"></span>fi</pre><span class="anchor" id="line-1139"></span><span class="anchor" id="line-1140"></span><p class="line862">The prehook with a <a href="/Tea4CUPS#capturing">virtual raw queue</a> is <span class="anchor" id="line-1141"></span><span class="anchor" id="line-1142"></span><p class="line867"><span class="anchor" id="line-1143"></span><span class="anchor" id="line-1144"></span><pre><span class="anchor" id="line-1-77"></span>prehook_rmdup : /usr/local/bin/rmdup $TEADATAFILE</pre><span class="anchor" id="line-1145"></span><span class="anchor" id="line-1146"></span><p class="line867">
<h3 id="Credits">Credits</h3>
<span class="anchor" id="line-1147"></span><span class="anchor" id="line-1148"></span><p class="line862">The writing of this page benefited greatly from the conributions made by Jerome Alet <tt>&lt;alet&nbsp;SPAMFREE&nbsp;AT&nbsp;librelogiciel&nbsp;DOT&nbsp;com&gt;</tt>, the author of <a class="http" href="http://www.pykota.com/software/tea4cups">Tea4CUPS</a>, on the <a class="http" href="http://lists.pykota.com/pipermail/tea4cups/">Tea4CUPS</a> and <a class="https" href="https://www.cups.org/lists.php?LIST=cups">CUPs user</a> mailing lists. <span class="anchor" id="line-1149"></span><span class="anchor" id="line-1150"></span><p class="line867">
<h3 id="See_Also">See Also</h3>
<span class="anchor" id="line-1151"></span><ul><li><p class="line891"><a href="/Printing">The Debian Printing Portal</a> <span class="anchor" id="line-1152"></span><span class="anchor" id="line-1153"></span></li></ul><p class="line867">
<h3 id="Finally">Finally</h3>
<span class="anchor" id="line-1154"></span><span class="anchor" id="line-1155"></span><p class="line874">Although the scripts on this page were tested on Jessie and are intended to be working scripts it is possible they are suboptimal for your needs. You are encouraged to correct any serious mistakes in them and submit ideas for using Tea4CUPS in novel or interesting ways. <span class="anchor" id="line-1156"></span><span class="anchor" id="line-1157"></span><span class="anchor" id="line-1158"></span><span class="anchor" id="line-1159"></span><p class="line867"><span class="anchor" id="line-1160"></span><p class="line867"><span class="anchor" id="line-1161"></span><span class="anchor" id="line-1162"></span><p class="line867"><hr /><p class="line874"> <span class="anchor" id="line-1163"></span><span class="anchor" id="line-1164"></span><p class="line867"><span class="anchor" id="line-1165"></span><span class="anchor" id="bottom"></span></div><div id="pagebottom"></div>
</div>


<div id="footer">
<p id="pageinfo" class="info" lang="en" dir="ltr">Tea4CUPS  (<a class="nbinfo" href="/Tea4CUPS?action=info" rel="nofollow">last modified 2018-03-14 18:24:40</a>)</p>

<ul id="credits">
<li><a href="https://www.debian.org/legal/privacy">Debian privacy policy</a><br></li><li><a href="https://moinmo.in/" title="This site uses the MoinMoin Wiki software.">MoinMoin Powered</a></li><li><a href="https://moinmo.in/Python" title="MoinMoin is written in Python.">Python Powered</a></li><li>Debian Wiki <a href="/Teams/DebianWiki">team</a>, <a href="https://bugs.debian.org/wiki.debian.org">bugs</a> and <a href="https://salsa.debian.org/debian/wiki.debian.org">config</a> available.</li><li>Hosting provided by <a href="https://www.man-da.de/">Metropolitan Area Network Darmstadt</a></li>
</ul>


</div>
</body>
</html>