forked from qzind/qz-print
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sample.html
1163 lines (1025 loc) · 51 KB
/
sample.html
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
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<html>
<!-- License: LGPL 2.1 or QZ INDUSTRIES SOURCE CODE LICENSE -->
<head><title>QZ Print Plugin</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript" src="js/3rdparty/deployJava.js"></script>
<script type="text/javascript" src="js/3rdparty/jquery-1.10.2.js"></script>
<script type="text/javascript" src="js/qz-websocket.js"></script>
<script type="text/javascript">
/**
* Re-use the new WebSockets deployment if available. If not, fallback on the Oracle deployment
*/
window["deployQZ"] = typeof(deployQZ) == "function" ? deployQZ : deployQZApplet;
function deployQZApplet() {
console.log('Starting deploy of qz applet');
var attributes = {id: "qz", code:'qz.PrintApplet.class',
archive:'../qz-print.jar', width:1, height:1};
var parameters = {jnlp_href: '../qz-print_jnlp.jnlp',
cache_option:'plugin', disable_logging:'false',
initial_focus:'false', separate_jvm:'true'};
if (deployJava.versionCheck("1.7+") == true) {}
else if (deployJava.versionCheck("1.6.0_45+") == true) {}
else if (deployJava.versionCheck("1.6+") == true) {
delete parameters['jnlp_href'];
}
deployJava.runApplet(attributes, parameters, '1.6');
}
/**
* Deploy tray version of QZ, or
* Optionally used to deploy multiple versions of the applet for mixed
* environments. Oracle uses document.write(), which puts the applet at the
* top of the page, bumping all HTML content down.
*/
deployQZ();
function getCertificate(callback) {
/*
$.ajax({
method: 'GET',
url: 'assets/auth/public-key.txt',
async: false,
success: callback // Data returned from ajax call should be the site certificate
});
*/
//Non-ajax method, only include public key and intermediate key
callback("-----BEGIN CERTIFICATE-----\n" +
"MIIFAzCCAuugAwIBAgICEAIwDQYJKoZIhvcNAQEFBQAwgZgxCzAJBgNVBAYTAlVT\n" +
"MQswCQYDVQQIDAJOWTEbMBkGA1UECgwSUVogSW5kdXN0cmllcywgTExDMRswGQYD\n" +
"VQQLDBJRWiBJbmR1c3RyaWVzLCBMTEMxGTAXBgNVBAMMEHF6aW5kdXN0cmllcy5j\n" +
"b20xJzAlBgkqhkiG9w0BCQEWGHN1c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bVhC7qZl+V1BITfx6mGc4ayke7C9Hm57X0\n" +
"ak/NerAC/QXNs/bF17b+zsUt2ja5NVS8dDSC4JAkM1dD64Y26leYbPybB+FgOxFu\n" +
"wou9gFxzwbdGLCGboi0lNLjEysHJBi90KjPUETbzMmoilHNJXw7egIo8yS5eq8RH\n" +
"i2lS0GsQjYFMvplNVMATDXUPm9MKpCbZ7IlJ5eekhWqvErddcHbzCuUBkDZ7wX/j\n" +
"unk/3DyXdTsSGuZk3/fLEsc4/YTujpAjVXiA1LCooQJ7SmNOpUa66TPz9O7Ufkng\n" +
"+CoTSACmnlHdP7U9WLr5TYnmL9eoHwtb0hwENe1oFC5zClJoSX/7DRexSJfB7YBf\n" +
"vn6JA2xy4C6PqximyCPisErNp85GUcZfo33Np1aywFv9H+a83rSUcV6kpE/jAZio\n" +
"5qLpgIOisArj1HTM6goDWzKhLiR/AeG3IJvgbpr9Gr7uZmfFyQzUjvkJ9cybZRd+\n" +
"G8azmpBBotmKsbtbAU/I/LVk8saeXznshOVVpDRYtVnjZeAneso7\n" +
"-----END CERTIFICATE-----\n" +
"--START INTERMEDIATE CERT--\n" +
"-----BEGIN CERTIFICATE-----\n" +
"MIIFEjCCA/qgAwIBAgICEAAwDQYJKoZIhvcNAQELBQAwgawxCzAJBgNVBAYTAlVT\n" +
"MQswCQYDVQQIDAJOWTESMBAGA1UEBwwJQ2FuYXN0b3RhMRswGQYDVQQKDBJRWiBJ\n" +
"bmR1c3RyaWVzLCBMTEMxGzAZBgNVBAsMElFaIEluZHVzdHJpZXMsIExMQzEZMBcG\n" +
"A1UEAwwQcXppbmR1c3RyaWVzLmNvbTEnMCUGCSqGSIb3DQEJARYYc3VwcG9ydEBx\n" +
"emluZHVzdHJpZXMuY29tMB4XDTE1MDMwMjAwNTAxOFoXDTM1MDMwMjAwNTAxOFow\n" +
"gZgxCzAJBgNVBAYTAlVTMQswCQYDVQQIDAJOWTEbMBkGA1UECgwSUVogSW5kdXN0\n" +
"cmllcywgTExDM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BTADAQH/MA0GCSqGSIb3DQEBCwUAA4IBAQAJIO8SiNr9jpLQ\n" +
"eUsFUmbueoxyI5L+P5eV92ceVOJ2tAlBA13vzF1NWlpSlrMmQcVUE/K4D01qtr0k\n" +
"gDs6LUHvj2XXLpyEogitbBgipkQpwCTJVfC9bWYBwEotC7Y8mVjjEV7uXAT71GKT\n" +
"x8XlB9maf+BTZGgyoulA5pTYJ++7s/xX9gzSWCa+eXGcjguBtYYXaAjjAqFGRAvu\n" +
"pz1yrDWcA6H94HeErJKUXBakS0Jm/V33JDuVXY+aZ8EQi2kV82aZbNdXll/R6iGw\n" +
"2ur4rDErnHsiphBgZB71C5FD4cdfSONTsYxmPmyUb5T+KLUouxZ9B0Wh28ucc1Lp\n" +
"rbO7BnjW\n" +
"-----END CERTIFICATE-----\n");
}
function signRequest(toSign, callback) {
/*
$.ajax({
method: 'GET',
contentType: "text/plain",
url: '/secure/url/for/sign-message.php?request=' + toSign,
async: false,
success: callback // Data returned from ajax call should be the signature
});
*/
//Send unsigned messages to socket - users will then have to Allow/Deny each print request
callback();
}
/**
* Automatically gets called when applet has loaded.
*/
function qzReady() {
// If the qz object hasn't been created, fallback on the <applet> tags
if (!qz) {
window["qz"] = document.getElementById('qz');
}
var title = document.getElementById("title");
if (qz) {
try {
title.innerHTML = title.innerHTML + " " + qz.getVersion();
document.getElementById("qz-status").style.background = "#F0F0F0";
} catch(err) { // LiveConnect error, display a detailed message
document.getElementById("qz-status").style.background = "#F5A9A9";
alert("ERROR: \nThe applet did not load correctly. Communication to the " +
"applet has failed, likely caused by Java Security Settings. \n\n" +
"CAUSE: \nJava 7 update 25 and higher block LiveConnect calls " +
"once Oracle has marked that version as outdated, which " +
"is likely the cause. \n\nSOLUTION: \n 1. Update Java to the latest " +
"Java version \n (or)\n 2. Lower the security " +
"settings from the Java Control Panel.");
}
}
}
function qzSocketError(event) {
document.getElementById("qz-status").style.background = "#F5A9A9";
console.log('Error:');
console.log(event);
alert("Connection had an error:\n"+ event.reason);
}
function qzSocketClose(event) {
document.getElementById("qz-status").style.background = "#A0A0A0";
console.log('Close:');
console.log(event);
alert("Connection was closed:\n"+ event.reason);
}
function qzNoConnection() {
alert("Unable to connect to QZ, is it running?");
//run deploy applet After page load
var content = '';
var oldWrite = document.write;
document.write = function(text) {
content += text;
};
deployQZApplet();
var newElem = document.createElement('ins');
newElem.innerHTML = content;
document.write = oldWrite;
document.body.appendChild(newElem);
}
/**
* Returns whether or not the applet is not ready to print.
* Displays an alert if not ready.
*/
function notReady() {
// If applet is not loaded, display an error
if (!isLoaded()) {
return true;
}
// If a printer hasn't been selected, display a message.
else if (!qz.getPrinter()) {
alert('Please select a printer first by using the "Detect Printer" button.');
return true;
}
return false;
}
/**
* Returns is the applet is not loaded properly
*/
function isLoaded() {
if (!qz) {
alert('Error:\n\n\tPrint plugin is NOT loaded!');
return false;
} else {
try {
if (!qz.isActive()) {
alert('Error:\n\n\tPrint plugin is loaded but NOT active!');
return false;
}
} catch (err) {
alert('Error:\n\n\tPrint plugin is NOT loaded properly!');
return false;
}
}
return true;
}
/**
* Automatically gets called when "qz.print()" is finished.
*/
function qzDonePrinting() {
// Alert error, if any
if (qz.getException()) {
alert('Error printing:\n\n\t' + qz.getException().getLocalizedMessage());
qz.clearException();
return;
}
// Alert success message
alert('Successfully sent print data to "' + qz.getPrinter() + '" queue.');
}
/***************************************************************************
* Prototype function for finding the "default printer" on the system
* Usage:
* qz.findPrinter();
* window['qzDoneFinding'] = function() { alert(qz.getPrinter()); };
***************************************************************************/
function useDefaultPrinter() {
if (isLoaded()) {
// Searches for default printer
qz.findPrinter();
// Automatically gets called when "qz.findPrinter()" is finished.
window['qzDoneFinding'] = function() {
// Alert the printer name to user
var printer = qz.getPrinter();
alert(printer !== null ? 'Default printer found: "' + printer + '"':
'Default printer ' + 'not found');
// Remove reference to this function
window['qzDoneFinding'] = null;
};
}
}
/***************************************************************************
* Prototype function for printing raw commands directly to the filesystem
* Usage:
* qz.append("\n\nHello world!\n\n");
* qz.printToFile("C:\\Users\\Jdoe\\Desktop\\test.txt");
***************************************************************************/
function printToFile() {
if (isLoaded()) {
// Any printer is ok since we are writing to the filesystem instead
qz.findPrinter();
// Automatically gets called when "qz.findPrinter()" is finished.
window['qzDoneFinding'] = function() {
// Send characters/raw commands to qz using "append"
// Hint: Carriage Return = \r, New Line = \n, Escape Double Quotes= \"
qz.append('\nN\n');
qz.append('q609\n');
qz.append('Q203,26\n');
qz.append('B5,26,0,1A,3,7,152,B,"1234"\n');
qz.append('A310,26,0,3,1,1,N,"SKU 00000 MFG 0000"\n');
qz.append('A310,56,0,3,1,1,N,"QZ PRINT APPLET"\n');
qz.append('A310,86,0,3,1,1,N,"TEST PRINT SUCCESSFUL"\n');
qz.append('A310,116,0,3,1,1,N,"FROM SAMPLE.HTML"\n');
qz.append('A310,146,0,3,1,1,N,"QZINDUSTRIES.COM"\n');
qz.append('P1\n');
// Send characters/raw commands to file
// i.e. qz.printToFile("\\\\server\\printer");
// qz.printToFile("/home/user/test.txt");
qz.printToFile("C:\\tmp\\qz-print_test-print.txt");
// Remove reference to this function
window['qzDoneFinding'] = null;
};
}
}
/***************************************************************************
* Prototype function for printing raw commands directly to a hostname or IP
* Usage:
* qz.append("\n\nHello world!\n\n");
* qz.printToHost("192.168.1.254", 9100);
***************************************************************************/
function printToHost() {
if (isLoaded()) {
// Any printer is ok since we are writing to a host address instead
qz.findPrinter();
// Automatically gets called when "qz.findPrinter()" is finished.
window['qzDoneFinding'] = function() {
// Send characters/raw commands to qz using "append"
// Hint: Carriage Return = \r, New Line = \n, Escape Double Quotes= \"
qz.append('\nN\n');
qz.append('q609\n');
qz.append('Q203,26\n');
qz.append('B5,26,0,1A,3,7,152,B,"1234"\n');
qz.append('A310,26,0,3,1,1,N,"SKU 00000 MFG 0000"\n');
qz.append('A310,56,0,3,1,1,N,"QZ PRINT APPLET"\n');
qz.append('A310,86,0,3,1,1,N,"TEST PRINT SUCCESSFUL"\n');
qz.append('A310,116,0,3,1,1,N,"FROM SAMPLE.HTML"\n');
qz.append('A310,146,0,3,1,1,N,"QZINDUSTRIES.COM"\n');
qz.append('P1\n');
// qz.printToHost(String hostName, int portNumber);
// qz.printToHost("192.168.254.254"); // Defaults to 9100
qz.printToHost("192.168.1.254", 9100);
// Remove reference to this function
window['qzDoneFinding'] = null;
};
}
}
/***************************************************************************
* Prototype function for finding the closest match to a printer name.
* Usage:
* qz.findPrinter('zebra');
* window['qzDoneFinding'] = function() { alert(qz.getPrinter()); };
***************************************************************************/
function findPrinter(name) {
// Get printer name from input box
var p = document.getElementById('printer');
if (name) {
p.value = name;
}
if (isLoaded()) {
// Searches for locally installed printer with specified name
qz.findPrinter(p.value);
// Automatically gets called when "qz.findPrinter()" is finished.
window['qzDoneFinding'] = function() {
var p = document.getElementById('printer');
var printer = qz.getPrinter();
// Alert the printer name to user
alert(printer !== null ? 'Printer found: "' + printer +
'" after searching for "' + p.value + '"' : 'Printer "' +
p.value + '" not found.');
// Remove reference to this function
window['qzDoneFinding'] = null;
};
}
}
/***************************************************************************
* Prototype function for listing all printers attached to the system
* Usage:
* qz.findPrinter('\\{dummy_text\\}');
* window['qzDoneFinding'] = function() { alert(qz.getPrinters()); };
***************************************************************************/
function findPrinters() {
if (isLoaded()) {
// Searches for a locally installed printer with a bogus name
qz.findPrinter('\\{bogus_printer\\}');
// Automatically gets called when "qz.findPrinter()" is finished.
window['qzDoneFinding'] = function() {
// Get the CSV listing of attached printers
var printers = qz.getPrinters().replace(/,/g, '\n');
alert(printers);
// Remove reference to this function
window['qzDoneFinding'] = null;
};
}
}
/***************************************************************************
* Prototype function for printing raw EPL commands
* Usage:
* qz.append('\nN\nA50,50,0,5,1,1,N,"Hello World!"\n');
* qz.print();
***************************************************************************/
function printEPL() {
if (notReady()) { return; }
// Send characters/raw commands to qz using "append"
// This example is for EPL. Please adapt to your printer language
// Hint: Carriage Return = \r, New Line = \n, Escape Double Quotes= \"
qz.append('\nN\n');
qz.append('q609\n');
qz.append('Q203,26\n');
qz.append('B5,26,0,1A,3,7,152,B,"1234"\n');
qz.append('A310,26,0,3,1,1,N,"SKU 00000 MFG 0000"\n');
qz.append('A310,56,0,3,1,1,N,"QZ PRINT APPLET"\n');
qz.append('A310,86,0,3,1,1,N,"TEST PRINT SUCCESSFUL"\n');
qz.append('A310,116,0,3,1,1,N,"FROM SAMPLE.HTML"\n');
qz.append('A310,146,0,3,1,1,N,"QZINDUSTRIES.COM"\n');
qz.appendImage(getPath() + 'assets/img/image_sample_bw.png', 'EPL', 150, 300);
// Automatically gets called when "qz.appendImage()" is finished.
window['qzDoneAppending'] = function() {
// Append the rest of our commands
qz.append('\nP1,1\n');
// Tell the applet to print.
qz.print();
// Remove reference to this function
window['qzDoneAppending'] = null;
};
}
/***************************************************************************
* Prototype function for printing raw ESC/POS commands
* Usage:
* qz.append('\n\n\nHello world!\n');
* qz.print();
***************************************************************************/
function printESCP() {
if (notReady()) { return; }
// Append a png in ESCP format with single pixel density
qz.appendImage(getPath() + "assets/img/image_sample_bw.png", "ESCP", "single");
// Automatically gets called when "qz.appendImage()" is finished.
window["qzDoneAppending"] = function() {
// Append the rest of our commands
qz.append('\nPrinted using qz-print plugin.\n\n\n\n\n\n');
// Tell the apple to print.
qz.print();
// Remove any reference to this function
window['qzDoneAppending'] = null;
};
}
/***************************************************************************
* Prototype function for printing raw ZPL commands
* Usage:
* qz.append('^XA\n^FO50,50^ADN,36,20^FDHello World!\n^FS\n^XZ\n');
* qz.print();
***************************************************************************/
function printZPL() {
if (notReady()) { return; }
// Send characters/raw commands to qz using "append"
// This example is for ZPL. Please adapt to your printer language
// Hint: Carriage Return = \r, New Line = \n, Escape Double Quotes= \"
qz.append('^XA\n');
qz.append('^FO50,50^ADN,36,20^FDPRINTED USING QZ PRINT PLUGIN ' + qz.getVersion() + '\n');
qz.appendImage(getPath() + 'assets/img/image_sample_bw.png', 'ZPLII');
// Automatically gets called when "qz.appendImage()" is finished.
window['qzDoneAppending'] = function() {
// Append the rest of our commands
qz.append('^FS\n');
qz.append('^XZ\n');
// Tell the apple to print.
qz.print();
// Remove any reference to this function
window['qzDoneAppending'] = null;
};
}
/***************************************************************************
* Prototype function for printing syntactically proper raw commands directly
* to a EPCL capable card printer, such as the Zebra P330i. Uses helper
* appendEPCL() to add the proper NUL, data length, escape character and
* newline per spec: https://km.zebra.com/kb/index?page=content&id=SO8390
* Usage:
* appendEPCL('A1');
* qz.print();
***************************************************************************/
function printEPCL() {
if (notReady()) { return; }
appendEPCL('+RIB 4'); // Monochrome ribbon
appendEPCL('F'); // Clear monochrome print buffer
appendEPCL('+C 8'); // Adjust monochrome intensity
appendEPCL('&R'); // Reset magnetic encoder
appendEPCL('&CDEW 0 0'); // Set R/W encoder to ISO default
appendEPCL('&CDER 0 0'); // Set R/W encoder to ISO default
appendEPCL('&SVM 0'); // Disable magnetic encoding verifications
appendEPCL('T 80 600 0 1 0 45 1 QZ INDUSTRIES'); // Write text buffer
appendEPCL('&B 1 123456^INDUSTRIES/QZ^789012'); // Write mag strip buffer
appendEPCL('&E*'); // Encode magnetic data
appendEPCL('I 10'); // Print card (10 returns to print ready pos.)
appendEPCL('MO'); // Move card to output hopper
qz.printToFile("C:\\tmp\\EPCL_Proper.txt");
//qz.print();
}
/**
* EPCL helper function that appends a single line of EPCL data, taking into
* account special EPCL NUL characters, data length, escape character and
* carriage return
*/
function appendEPCL(data) {
if (data == null || data.length == 0) {
return alert('Empty EPCL data, skipping!');
}
// Data length for this command, in 2 character Hex (base 16) format
var len = (data.length + 2).toString(16);
len = len.length < 2 ? '0' + len : len;
// Append three NULs
qz.appendHex('x00x00x00');
// Append our command length, in base16 (hex)
qz.appendHex('x' + len);
// Append our command
qz.append(data);
// Append carriage return
qz.append('\r');
}
/***************************************************************************
* Prototype function for printing raw base64 encoded commands
* Usage:
* qz.append64('SGVsbG8gV29ybGQh');
* qz.print();
***************************************************************************/
function print64() {
if (notReady()) { return; }
// Send base64 encoded characters/raw commands to qz using "append64"
// This will automatically convert provided base64 encoded text into
// text/ascii/bytes, etc. This example is for EPL and contains an
// embedded image. Please adapt to your printer language
qz.append64('Ck4KcTYwOQpRMjAzLDI2CkI1LDI2LDAsMUEsMyw3LDE1MixCLCIxMjM0IgpBMzEwLDI2LDAsMywx' +
'LDEsTiwiU0tVIDAwMDAwIE1GRyAwMDAwIgpBMzEwLDU2LDAsMywxLDEsTiwiUVogUFJJTlQgQVBQ' +
'TEVUIgpBMzEwLDg2LDAsMywxLDEsTiwiVEVTVCBQUklOVCBTVUNDRVNTRlVMIgpBMzEwLDExNiww' +
'LDMsMSwxLE4sIkZST00gU0FNUExFLkhUTUwiCkEzMTAsMTQ2LDAsMywxLDEsTiwiUVpJTkRVU1RS' +
'SUVTLkNPTSIKR1cxNTAsMzAwLDMyLDEyOCz/////////6SSSX///////////////////////////' +
'//////////6UlUqX////////////////////////////////////8kqkpKP/////////////////' +
'//////////////////6JUpJSVf//////////////////////////////////9KpKVVU+////////' +
'//////////////////////////8KSSlJJf5/////////////////////////////////9KUqpVU/' +
'/7////////////////////////////////9KqUkokf//P///////////////////////////////' +
'+VKUqpZP//+P///////////////////////////////ElKUlSf///9f/////////////////////' +
'////////+ipSkqin////y/////////////////////////////+lVUpUlX/////r////////////' +
'/////////////////qlJKUql/////+n////////////////////////////BFKVKUl//////8v//' +
'/////////////////////////zVSlKUp///////0f//////////////////////////wiSlSUpf/' +
'//////q///////////////////////////KqlJUpV///////+R//////////////////////////' +
'4UlKSpSX///////9T/////////6L///////////////BKlKpSqP///////1X////////0qg/23/V' +
'VVVVVVf//8CSlJKklf///////kv///////+pS0/JP8AAAAAAB///wFSlSSpV///////+pf//////' +
'/pUoq+qfwAAAAAAH//+AClSqpUT///////9S///////8pJUlkr+AAAAAAA///4AFJSSSUv//////' +
'/yl///////KVUpTUv8AAAAAAH///gBKSqlVU////////lX//////6UkqoiU/wAAAAAA///+ABKpJ' +
'Uko////////JH//////UpIiqlJ/AAAAAAD///wACkSUpJX///////6q//////6pVVSqiv4AAAAAA' +
'f///AAJVVIqpP///////pI//////pSVtSSq/wAAAAAD///8AAJSlVJVf///////Sp/////8Sq//U' +
'qL/ttttoAP///wAAUpVSpJ///////+pT/////qkn//UlH/////AB////AABKUSpSX///////5Sn/' +
'///+lJ//+pS/////4AP///8AABKUkpVP///////ylP////1Kv//+qr/////AA////4AAKVVJUl//' +
'/////+lKf////KS///8kv////8AH////gAAKSSpJR///////9Kq////9Kv///5Kf////gAf///+A' +
'AAUlUqov///////1JT////lS////qn////8AD////4AABKpKSqf///////Skj///+kr////JH///' +
'/wAf////wAACkqUlK///////8pKv///ypf///9V////+AD/////AAAFKUVSj///////wqlP///JT' +
'////yR////wAP////8AAAFKqkpv///////JSlf//9Sv////U/////AB/////4AAAVIpKRf//////' +
'+ElV///pS////8of///4AP/////gAAASZVKr///////4qkj///Sn////0v////AA//////AAABUS' +
'VJH///////glJn//8pP////KH///8AH/////+AAACtUlVf//////+ClRP//qV////9K////gA///' +
'///4AAACEpJK///////8BSqf/+lX////yr///8AD//////wAAAVUqVH///////gUlU//5Rf////R' +
'P///gAf//////gAAApKqTP//////8AVSV//pU////6qf//+AD//////+AAAAqkki//////8AEpVL' +
'/+qP////1L///wAP//////4AAACSVVB/////+AFUpKX/9KP////Sv//+AB///////AAAAEqSgH//' +
'//+ACkpSUv/lV////6k///4AP//////+AAAAUlSgf////gAJKRUpf/ST////1J///AA///////4A' +
'AAAVJVB////gAtVFUpV/8lX///+Vf//4AH///////gAAABKSSD///wASSVVJSR/1Vf///8kf//gA' +
'///////+AAAABVUof//4AElUpKqqv/SL////1L//8AD///////4AAAABJJQ//8AFVJKVKSSP+qj/' +
'///Kv//gAf///////gAAAAKSpT/+ACkqSlKUkqf5Rf///6S//+AD///////+AAAAAKqpP/ABJKVS' +
'klKqU/xUf///qp//wAP///////4AAAAAkko+gASVKUlVKlKX/VK///9Sf/+AB////////gAAAACp' +
'UrgAKqVKVJKSlKf+Sl///0kf/4AP///////+AAAAABSVIAFJUlKqSUpKV/0pX//8qr//AA//////' +
'//8AAAAACklACSopKSVUqVKX/qpH//okv/4AH////////gAAAAAVVKBUpUqUkkpKSk//SSv/xVK/' +
'/AAAAAAD////AAAAAAJKWSUpVKVVUqVSp/+qqH9SlR/8AAAAAAH///4AAAAABSUklJSSlJJKUkpf' +
'/8klQFSo//gAAAAAA////wAAAAABVKqlUkqlSqkqqU//6pUqkkof8AAAAAAB/r//AAAAAAElEpSK' +
'qSlSSpJKL//pUqpVKr/wAAAAAAP8v/8AAAAAAJLKUqkkpSqkqSVf//yUkpKSv+AAAAAAAfqf/wAA' +
'AAAAVClKVVUoklUqqp///UpKVVS/wAAAAAAD+S//AAAAAAAlpSkkkpVKkpKSX///JVKTpR+AAAAA' +
'AAH9X/8AAAAAABRUpVJUqqSpSUlf///SSk/Sv4AAAAAAA/y//wAAAAAAFSVUlSUkUkpUqr////VS' +
'v9S/AAAAAAAB/3//AAAAAAAFUkpSlJMqqUpJP////13/pT////////////8AAAAAAAEpJSlSqUkk' +
'pVS////////Un////////////wAAAAAABJVSlSpUqpUpJX///////8q/////////////gAAAAAAC' +
'pSqkkpKSUpSSP///////5L////////////+AAAAAAACSkVVKSklKpVV///////+SX///////////' +
'/4AAAAAAAFSqJKlSqqiVSX///////9U/////////////gAAAAAAASpVSlSkklVJU////////yr//' +
'//////////+AAAAAAAAkpJSklKpKSUp////////kn////////////4AAAAAAABJSqlKqkqUqVf//' +
'/////5K/////////////gAAAAAAACpUlKpJKUqlI////////1L////////////+AAAAAAAAFSVKS' +
'SqkpFKX////////SX////////////4AAAAAAAAiklKlSSpTKKv///////9U/////////////wAAA' +
'AAAABSpSlSqlSiVJ////////pV/////////////AAAAAAAAVUpSkklSlUqX////////Uv///////' +
'/////8AAAAAAAAkqUpVJJSqpVf///////8pf////////////4AAAAAAAFJKUpKqUpJUT////////' +
'4r/////////////wAAAAAAAKqVKVKUqSSVX///////+Uv/////////////gAAAAAAASUlKSkpKql' +
'S////////+qf/////////////AAAAAAAEkpKUlUpJJCn////////iH///////////w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P//gAAAAA' +
'AAAAAAAP8AAAD4fh+A/A/w/wAAB8AAeA/Af/+AAAAAAAAAAAAA/AAAAPg/HwB8B+B+AAAHwAB4B8' +
'Af/4AAAAAAAAAAAADwAAAA+B+fAHwH4H4AAAfAAHgHwAf4AAAAAAAAAAAAAIAAAAD4H/8Afgfgfg' +
'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
'AAAAAAAAAAAAAAAAAAAAAAAAClAxLDEK');
// Tell the apple to print.
qz.print();
}
/***************************************************************************
* Prototype function for controlling print spooling between pages
* Usage:
* qz.setEndOfDocument('P1,1\r\n');
* qz.setDocumentsPerSpool('5');
* qz.appendFile('/path/to/file.txt');
* window['qzDoneAppending'] = function() { qz.print(); };
***************************************************************************/
function printPages() {
if (notReady()) { return; }
// Mark the end of a label, in this case P1 plus a newline character
// qz-print knows to look for this and treat this as the end of a "page"
// for better control of larger spooled jobs (i.e. 50+ labels)
qz.setEndOfDocument('P1,1\r\n');
// The amount of labels to spool to the printer at a time. When
// qz-print counts this many `EndOfDocument`'s, a new print job will
// automatically be spooled to the printer and counting will start
// over.
qz.setDocumentsPerSpool("2");
qz.appendFile(getPath() + "assets/epl_multiples.txt");
// Automatically gets called when "qz.appendFile()" is finished.
window['qzDoneAppending'] = function() {
// Tell the applet to print.
qz.print();
// Remove reference to this function
window['qzDoneAppending'] = null;
};
}
/***************************************************************************
* Prototype function for printing a single XML node containing base64
* encoded data.
* Usage:
* qz.appendXML('/path/to/file.xml');
* window['qzDoneAppending'] = function() { qz.print(); };
***************************************************************************/
function printXML() {
if (notReady()) { return; }
// Appends the contents of an XML file from a SOAP response, etc.
// First parameter: A valid complete URL is required for the XML file.
// Second parameter: A valid XML tag/node name containing
// base64 encoded data, i.e. <node_1>aGVsbG8gd29ybGQ=</node_1>
// Example:
// qz.appendXML("http://yoursite.com/zpl.xml", "node_1");
qz.appendXML(getPath() + "assets/zpl_sample.xml", "v7:Image");
// Automatically gets called when "qz.appendXML()" is finished.
window['qzDoneAppending'] = function() {
// Tell the applet to print.
qz.print();
// Remove reference to this function
window['qzDoneAppending'] = null;
};
}
/***************************************************************************
* Prototype function for printing hexadecimal formatted raw data
*
* Usage:
* qz.appendHex('00AABBCCDDEEFF');
* qz.appendHex('x00xAAxBBxCCxDDxEExFF');
* qz.print();
***************************************************************************/
function printHex() {
if (notReady()) { return; }
// Since 1.5.4, No backslashes needed (fixes \x00 NUL JavaScript bug)
// Can be in format "1B00" or "x1Bx00"
// EPL Sample Provided
qz.appendHex("4e0d0a713630390d0a513230332c32360d0a42352c32362c");
qz.appendHex("302c31412c332c372c3135322c422c2231323334220d0a41");
qz.appendHex("3331302c32362c302c332c312c312c4e2c22534b55203030");
qz.appendHex("303030204d46472030303030220d0a413331302c35362c30");
qz.appendHex("2c332c312c312c4e2c22515a205072696e7420506c756769");
qz.appendHex("6e220d0a413331302c38362c302c332c312c312c4e2c2254");
qz.appendHex("657374207072696e74207375636365737366756c220d0a41");
qz.appendHex("3331302c3131362c302c332c312c312c4e2c2266726f6d20");
qz.appendHex("73616d706c652e68746d6c220d0a413331302c3134362c30");
qz.appendHex("2c332c312c312c4e2c227072696e7448657828292066756e");
qz.appendHex("6374696f6e2e220d0a50312c310d0a");
// Send characters/raw commands to printer
qz.print();
}
/***************************************************************************
* Prototype function for printing a text or binary file containing raw
* print commands.
* Usage:
* qz.appendFile('/path/to/file.txt');
* window['qzDoneAppending'] = function() { qz.print(); };
***************************************************************************/
function printFile(file) {
if (notReady()) { return; }
// Append raw or binary text file containing raw print commands
qz.appendFile(getPath() + "assets/" + file);
// Automatically gets called when "qz.appendFile()" is finished.
window['qzDoneAppending'] = function() {
// Tell the applet to print.
qz.print();
// Remove reference to this function
window['qzDoneAppending'] = null;
};
}
/***************************************************************************
* Prototype function for printing a graphic to a PostScript capable printer.
* Not to be used in combination with raw printers.
* Usage:
* qz.appendImage('/path/to/image.png');
* window['qzDoneAppending'] = function() { qz.printPS(); };
***************************************************************************/
function printImage(scaleImage) {
if (notReady()) { return; }
// Optional, set up custom page size. These only work for PostScript printing.
// setPaperSize() must be called before setAutoSize(), setOrientation(), etc.
if (scaleImage) {
qz.setPaperSize("8.5in", "11.0in"); // US Letter
//qz.setPaperSize("210mm", "297mm"); // A4
qz.setAutoSize(true);
//qz.setOrientation("landscape");
//qz.setOrientation("reverse-landscape");
}
//qz.setCopies(3);
qz.setCopies(parseInt(document.getElementById("copies").value));
// Append our image (only one image can be appended per print)
qz.appendImage(getPath() + "assets/img/image_sample.png");
// Automatically gets called when "qz.appendImage()" is finished.
window['qzDoneAppending'] = function() {
// Tell the applet to print PostScript.
qz.printPS();
// Remove reference to this function
window['qzDoneAppending'] = null;
};
}
/***************************************************************************
* Prototype function for printing a PDF to a PostScript capable printer.
* Not to be used in combination with raw printers.
* Usage:
* qz.appendPDF('/path/to/sample.pdf');
* window['qzDoneAppending'] = function() { qz.printPS(); };
***************************************************************************/
function printPDF() {
if (notReady()) { return; }
// Append our pdf (only one pdf can be appended per print)
qz.appendPDF(getPath() + "assets/pdf_sample.pdf");
//qz.setCopies(3);
qz.setCopies(parseInt(document.getElementById("copies").value));
// Automatically gets called when "qz.appendPDF()" is finished.
window['qzDoneAppending'] = function() {
// Tell the applet to print PostScript.
qz.printPS();
// Remove reference to this function
window['qzDoneAppending'] = null;
};
}
/***************************************************************************
* Prototype function for printing plain HTML 1.0 to a PostScript capable
* printer. Not to be used in combination with raw printers.
* Usage:
* qz.appendHTML('<h1>Hello world!</h1>');
* qz.printPS();
***************************************************************************/
function printHTML() {
if (notReady()) { return; }
// Preserve formatting for white spaces, etc.
var colA = fixHTML('<h2>* QZ Print Plugin HTML Printing *</h2>');
colA = colA + '<color=red>Version:</color> ' + qz.getVersion() + '<br />';
colA = colA + '<color=red>Visit:</color> http://code.google.com/p/jzebra';
// HTML image
var colB = '<img src="' + getPath() + 'assets/img/image_sample.png">';
//qz.setCopies(3);
qz.setCopies(parseInt(document.getElementById("copies").value));
// Append our image (only one image can be appended per print)
qz.appendHTML(
'<html>' +
'<table face="monospace" border="1px">' +
'<tr height="6cm">' +
'<td valign="top">' + colA + '</td>' +
'<td valign="top">' + colB + '</td>' +
'</tr>' +
'</table>' +
'</html>'
);
qz.printHTML();
}
/***************************************************************************
* Prototype function for getting the primary IP or Mac address of a computer
* Usage:
* qz.findNetworkInfo();
* window['qzDoneFindingNetwork'] = function() {alert(qz.getMac() + ',' +
* qz.getIP()); };
***************************************************************************/
function listNetworkInfo() {
if (isLoaded()) {
// Makes a quick connection to www.google.com to determine the active interface
// Note, if you don't wish to use google.com, you can customize the host and port
// qz.getNetworkUtilities().setHostname("qzindustries.com");
// qz.getNetworkUtilities().setPort(80);
qz.findNetworkInfo();
// Automatically gets called when "qz.findPrinter()" is finished.
window['qzDoneFindingNetwork'] = function() {
alert("Primary adapter found: " + qz.getMac() + ", IP: " + qz.getIP());
// Remove reference to this function
window['qzDoneFindingNetwork'] = null;
};
}
}
/***************************************************************************
* Prototype function for printing an HTML screenshot of the existing page
* Usage: (identical to appendImage(), but uses html2canvas for png rendering)
* qz.setPaperSize("8.5in", "11.0in"); // US Letter
* qz.setAutoSize(true);
* qz.appendImage($("canvas")[0].toDataURL('image/png'));
***************************************************************************/
function printHTML5Page() {
$("#qz-status").html2canvas({
canvas: hidden_screenshot,
onrendered: function() {
if (notReady()) { return; }
// Optional, set up custom page size. These only work for PostScript printing.
// setPaperSize() must be called before setAutoSize(), setOrientation(), etc.
qz.setPaperSize("8.5in", "11.0in"); // US Letter
qz.setAutoSize(true);
qz.appendImage($("canvas")[0].toDataURL('image/png'));
//qz.setCopies(3);
qz.setCopies(parseInt(document.getElementById("copies").value));
// Automatically gets called when "qz.appendFile()" is finished.
window['qzDoneAppending'] = function() {
// Tell the applet to print.
qz.printPS();
// Remove reference to this function
window['qzDoneAppending'] = null;
};
}
});
}
/***************************************************************************
* Prototype function for logging a PostScript printer's capabilities to the
* java console to expose potentially new applet features/enhancements.
* Warning, this has been known to trigger some PC firewalls
* when it scans ports for certain printer capabilities.
* Usage: (identical to appendImage(), but uses html2canvas for png rendering)
* qz.setLogPostScriptFeatures(true);
* qz.appendHTML("<h1>Hello world!</h1>");
* qz.printPS();
***************************************************************************/
function logFeatures() {
if (isLoaded()) {
var logging = qz.getLogPostScriptFeatures();
console.log(logging);
qz.setLogPostScriptFeatures(!logging);
alert('Logging of PostScript printer capabilities to console set to "' + !logging + '"');
}
}
/***************************************************************************
* Prototype function to force Unix to use the terminal/command line for
* printing rather than the Java-to-CUPS interface. This will write the
* raw bytes to a temporary file, then execute a shell command.
* (i.e. lpr -o raw temp_file). This was created specifically for OSX but
* may work on several Linux versions as well.
* qz.useAlternatePrinting(true);
* qz.append('\n\nHello World!\n\n');
* qz.print();
***************************************************************************/
function useAlternatePrinting() {
if (isLoaded()) {
var alternate = qz.isAlternatePrinting();
qz.useAlternatePrinting(!alternate);
alert('Alternate CUPS printing set to "' + !alternate + '"');
}
}
/***************************************************************************
* Prototype function to list all available com ports available to this PC
* used for RS232 communication. Relies on jssc_qz.jar signed and in the
* /dist/ folder.
* qz.findPorts();
* window['qzDoneFindingPorts'] = function() { alert(qz.getPorts()); };
***************************************************************************/
function listSerialPorts() {
if (isLoaded()) {
// Search the PC for communication (RS232, COM, tty) ports
qz.findPorts();
// Automatically called when "qz.findPorts()" is finished
window['qzDoneFindingPorts'] = function() {
var ports = qz.getPorts().split(",");
for (var p in ports) {
if (p == 0) {
document.getElementById("port_name").value = ports[p];
}
alert(ports[p]);
}
// Remove reference to this function
window['qzDoneFindingPorts'] = null;
};
}
}
/***************************************************************************
* Prototype function to open the specified communication port for 2-way
* communication.
* qz.openPort('COM1');
* qz.openPort('/dev/ttyUSB0');
* window['qzDoneOpeningPort'] = function(port) { alert(port); };
***************************************************************************/
function openSerialPort() {
if (isLoaded()) {
qz.openPort(document.getElementById("port_name").value);
// Automatically called when "qz.openPort()" is finished (even if it fails to open)
window['qzDoneOpeningPort'] = function(portName) {
if (qz.getException()) {
alert("Could not open port [" + portName + "] \n\t" +
qz.getException().getLocalizedMessage());
qz.clearException();
} else {
alert("Port [" + portName + "] is open!");
}
};
}
}
/***************************************************************************
* Prototype function to close the specified communication port.
* qz.closePort('COM1');
* qz.closePort('/dev/ttyUSB0');
* window['qzDoneClosingPort'] = function(port) { alert(port); };
***************************************************************************/