-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
704 lines (601 loc) · 31 KB
/
index.html
File metadata and controls
704 lines (601 loc) · 31 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta name="description"
content="PrintHub is a simple library to print receipt with Bluetooth and USB printer.">
<meta name="keywords"
content="PrintHub, Bluetooth Printer, USB Printer, Receipt Printer, QR Code, Barcode">
<meta name="author" content="Dede Fuji Abdul">
<meta name="robots" content="index, follow">
<meta name="revisit-after" content="7 days">
<meta name="googlebot"
content="index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1">
<meta name="bingbot"
content="index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1">
<meta property="og:title" content="PrintHub - Thermal Printer Library">
<meta property="og:description"
content="PrintHub is a simple library to print receipt with Bluetooth and USB printer. Support QR Code and Barcode!">
<meta property="og:type" content="website">
<meta property="og:url" content="https://defuj.github.io/printhub">
<meta property="og:image"
content="https://defuj.github.io/printhub/assets/images/printhub.webp">
<meta property="og:site_name" content="PrintHub">
<meta property="og:locale" content="en_US">
<meta property="og:image:width" content="1200">
<meta property="og:image:height" content="630">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="PrintHub - Thermal Printer Library">
<meta name="twitter:description"
content="PrintHub is a simple library to print receipt with Bluetooth and USB printer. Support QR Code and Barcode!">
<meta name="twitter:image"
content="https://defuj.github.io/printhub/assets/images/printhub.webp">
<meta name="twitter:image:alt" content="PrintHub">
<meta name="twitter:site" content="@defuj17">
<link rel="icon"
href="https://defuj.github.io/printhub/assets/favicon.ico"
type="image/x-icon">
<link rel="canonical" href="https://defuj.github.io/printhub">
<title>PrintHub - Thermal Printer Demo</title>
<script src="https://cdn.tailwindcss.com"></script>
<script>
tailwind.config = {
theme: {
extend: {
colors: {
clifford: '#da373d',
}
},
fontFamily: {
sans: ['MerchantCopy', 'sans-serif'],
},
}
}
</script>
<style type="text/tailwindcss">
@layer base {
@font-face {
font-family: 'MerchantCopy';
font-style: normal;
font-weight: 400;
font-display: swap;
src: url('https://defuj.github.io/assets/fonts/MerchantCopy.ttf') format('truetype');
}
@font-face {
font-family: 'MerchantCopy';
font-style: normal;
font-weight: 700;
font-display: swap;
src: url('https://defuj.github.io/assets/fonts/MerchantCopyDoublesize.ttf') format('truetype');
}
@font-face {
font-family: 'MerchantCopy';
font-style: normal;
font-weight: 800;
font-display: swap;
src: url('https://defuj.github.io/assets/fonts/MerchantCopyWide.ttf') format('truetype');
}
}
.receipt-preview {
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}
.demo-btn {
transition: all 0.3s ease;
}
.demo-btn:hover {
transform: translateY(-2px);
box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}
</style>
</head>
<body
class="flex flex-col items-center justify-start w-full min-h-screen p-4 bg-gradient-to-br from-gray-100 to-gray-200">
<!-- Header -->
<div class="w-full max-w-6xl mb-8">
<div class="text-center mb-4">
<h1 class="text-4xl font-bold text-gray-800 mb-2">🖨️ PrintHub
Demo</h1>
<p class="text-gray-600">Thermal Printer Library with QR Code &
Barcode Support</p>
<p class="text-sm text-gray-500 mt-2">v1.2.1 - Full Featured
Demo</p>
</div>
</div>
<!-- Main Container -->
<div class="w-full max-w-6xl grid grid-cols-1 lg:grid-cols-2 gap-6">
<!-- Left Column - Receipt Preview -->
<div class="bg-white p-6 rounded-lg shadow-lg">
<h2 class="text-xl font-bold text-gray-800 mb-4 text-center">📄
Receipt Preview</h2>
<div
class="receipt-preview bg-white p-4 rounded shadow-md w-full max-w-[80mm] mx-auto">
<!-- Print Header -->
<div class="text-center">
<img class="mx-auto h-16"
src="https://www.sadigit.co.id/wp-content/uploads/2021/10/cropped-sadigit-logo.png"
alt="Logo">
<h1 class="text-xl font-bold">SADIGIT</h1>
<p class="text-sm">Jl. Kutamaya No.Ruko A, Kotakulon</p>
<p class="text-sm">Kec. Sumedang Sel., Sumedang
45311</p>
<p class="text-sm">0852-2299-9699</p>
</div>
<div class="mt-2 text-center text-sm">
<p>No.Transaksi: SDGT-ONL-0001</p>
<p>Kasir: Otongsuke</p>
<p>2024-10-23 10:20:18</p>
</div>
<hr class="my-2 border-t-2 border-dashed">
<!-- Print Items -->
<div class="text-sm">
<div class="flex justify-between">
<span>Nasi Goreng</span>
<span>Rp 25.000</span>
</div>
<div class="flex justify-between">
<span>Es Teh Manis</span>
<span>Rp 5.000</span>
</div>
<div class="flex justify-between">
<span>Ayam Bakar</span>
<span>Rp 30.000</span>
</div>
<div class="flex justify-between">
<span>Sambal Extra</span>
<span>Rp 3.000</span>
</div>
</div>
<hr class="my-2 border-t-2 border-dashed">
<!-- Print Total -->
<div class="text-sm">
<div class="flex justify-between">
<span>Subtotal:</span>
<span>Rp 63.000</span>
</div>
<div class="flex justify-between">
<span>Pajak (10%):</span>
<span>Rp 6.300</span>
</div>
<div class="flex justify-between font-bold">
<span>TOTAL:</span>
<span>Rp 69.300</span>
</div>
<div class="flex justify-between">
<span>Bayar:</span>
<span>Rp 100.000</span>
</div>
<div class="flex justify-between">
<span>Kembali:</span>
<span>Rp 30.700</span>
</div>
</div>
<!-- QR/Barcode Placeholder -->
<div class="my-3 text-center">
<div
class="bg-gray-200 h-24 flex items-center justify-center text-gray-500 text-xs rounded">
QR Code / Barcode<br>akan muncul di sini
</div>
</div>
<!-- Print Footer -->
<div class="text-center text-sm">
<p>Terima kasih atas kunjungan Anda!</p>
<p>Follow IG @sadigit.id</p>
</div>
</div>
</div>
<!-- Right Column - Controls -->
<div class="space-y-4">
<!-- Printer Settings -->
<div class="bg-white p-6 rounded-lg shadow-lg">
<h2 class="text-xl font-bold text-gray-800 mb-4">⚙️ Printer
Settings</h2>
<div class="space-y-4">
<!-- Printer Type -->
<div class="flex flex-col">
<label for="printerType"
class="font-semibold text-gray-700 mb-2">
Printer Type:
</label>
<select id="printerType"
class="px-4 py-3 bg-gray-50 border border-gray-300 rounded-lg text-gray-700 focus:outline-none focus:ring-2 focus:ring-blue-500">
<option value="bluetooth" selected>Bluetooth
Printer</option>
<option value="usb">USB Printer</option>
</select>
</div>
<!-- Paper Size -->
<div class="flex flex-col">
<label for="paperSize"
class="font-semibold text-gray-700 mb-2">
Paper Size:
</label>
<select id="paperSize"
class="px-4 py-3 bg-gray-50 border border-gray-300 rounded-lg text-gray-700 focus:outline-none focus:ring-2 focus:ring-blue-500">
<option value="58">58mm</option>
<option value="80" selected>80mm</option>
</select>
</div>
</div>
</div>
<!-- Demo Options -->
<div class="bg-white p-6 rounded-lg shadow-lg">
<h2 class="text-xl font-bold text-gray-800 mb-4">🎯 Demo
Options</h2>
<div class="grid grid-cols-1 sm:grid-cols-2 gap-3">
<!-- Basic Receipt -->
<button id="printBasic"
class="demo-btn px-4 py-3 text-white bg-blue-600 hover:bg-blue-700 rounded-lg font-semibold">
📄 Basic Receipt
</button>
<!-- Receipt with QR -->
<button id="printQR"
class="demo-btn px-4 py-3 text-white bg-green-600 hover:bg-green-700 rounded-lg font-semibold">
📱 Receipt + QR
</button>
<!-- Receipt with Barcode -->
<button id="printBarcode"
class="demo-btn px-4 py-3 text-white bg-purple-600 hover:bg-purple-700 rounded-lg font-semibold">
📊 Receipt + Barcode
</button>
<!-- Complete Receipt -->
<button id="printComplete"
class="demo-btn px-4 py-3 text-white bg-red-600 hover:bg-red-700 rounded-lg font-semibold">
⭐ Complete Demo
</button>
<!-- Image Test -->
<button id="printImage"
class="demo-btn px-4 py-3 text-white bg-yellow-600 hover:bg-yellow-700 rounded-lg font-semibold">
🖼️ Image Test
</button>
<!-- Text Formatting -->
<button id="printFormatting"
class="demo-btn px-4 py-3 text-white bg-indigo-600 hover:bg-indigo-700 rounded-lg font-semibold">
🎨 Text Format
</button>
</div>
</div>
<!-- Status -->
<div class="bg-white p-6 rounded-lg shadow-lg">
<h2 class="text-xl font-bold text-gray-800 mb-4">📊
Status</h2>
<div id="status"
class="text-sm text-gray-600 bg-gray-50 p-3 rounded-lg min-h-[60px]">
Ready to print. Select a demo option above.
</div>
</div>
<!-- Info -->
<div class="bg-blue-50 border border-blue-200 p-4 rounded-lg">
<h3 class="font-semibold text-blue-800 mb-2">ℹ️
Information</h3>
<ul class="text-sm text-blue-700 space-y-1">
<li>• Click any demo button to connect and print</li>
<li>• QR Codes support payment links and URLs</li>
<li>• Barcodes auto-adjust to paper width</li>
<li>• Works with Bluetooth & USB thermal printers</li>
</ul>
</div>
</div>
</div>
<!-- Footer -->
<div class="w-full max-w-6xl mt-8 text-center text-gray-600 text-sm">
<p>PrintHub v1.2.1 - Made with ❤️ by <a
href="https://github.com/defuj"
class="text-blue-600 hover:underline">Dede Fuji
Abdul</a></p>
<p class="mt-1">
<a href="https://github.com/defuj/printhub"
class="text-blue-600 hover:underline">GitHub</a> •
<a href="https://www.npmjs.com/package/printhub"
class="text-blue-600 hover:underline">NPM</a> •
<a href="https://defuj.github.io/printhub"
class="text-blue-600 hover:underline">Documentation</a>
</p>
</div>
<script
src="https://cdn.jsdelivr.net/npm/printhub@1.2.1/dist/index.global.js"></script>
<script defer>
let printerType = 'bluetooth';
let paperSize = '80';
// Update status
function updateStatus(message, type = 'info') {
const statusEl = document.getElementById('status');
const colors = {
info: 'bg-blue-50 text-blue-700 border-blue-200',
success: 'bg-green-50 text-green-700 border-green-200',
error: 'bg-red-50 text-red-700 border-red-200',
warning: 'bg-yellow-50 text-yellow-700 border-yellow-200'
};
statusEl.className = `text-sm p-3 rounded-lg min-h-[60px] border ${colors[type] || colors.info}`;
statusEl.textContent = message;
}
// Printer type change
document.getElementById('printerType').addEventListener('change', (e) => {
printerType = e.target.value;
updateStatus(`Printer type changed to: ${printerType === 'bluetooth' ? 'Bluetooth' : 'USB'}`, 'info');
});
// Paper size change
document.getElementById('paperSize').addEventListener('change', (e) => {
paperSize = e.target.value;
updateStatus(`Paper size changed to: ${paperSize}mm`, 'info');
});
// ===== PRINT FUNCTIONS =====
// 1. Basic Receipt
async function printBasicReceipt(print) {
updateStatus('Printing basic receipt...', 'info');
await print.putImageWithUrl(
"https://www.sadigit.co.id/wp-content/uploads/2021/10/cropped-sadigit-logo.png",
{ align: "center" }
);
await print.writeText("SADIGIT", {
align: "center",
bold: true,
size: "double",
});
await print.writeText(
"Jl. Kutamaya No.Ruko A, Kotakulon, Kec. Sumedang Sel.",
{ align: "center" }
);
await print.writeText("Kabupaten Sumedang, Jawa Barat 45311", { align: "center" });
await print.writeText("0852-2299-9699", { align: "center" });
await print.writeLineBreak();
await print.writeText("No.Transaksi: SDGT-ONL-0001", { align: "center" });
await print.writeText("Kasir: Otongsuke", { align: "center" });
await print.writeText("2024-10-23 10:20:18", { align: "center" });
await print.writeDashLine();
await print.writeTextWith2Column("Nasi Goreng", "Rp 25.000");
await print.writeTextWith2Column("Es Teh Manis", "Rp 5.000");
await print.writeTextWith2Column("Ayam Bakar", "Rp 30.000");
await print.writeTextWith2Column("Sambal Extra", "Rp 3.000");
await print.writeDashLine();
await print.writeTextWith2Column("Subtotal:", "Rp 63.000");
await print.writeTextWith2Column("Pajak (10%):", "Rp 6.300");
await print.writeTextWith2Column("TOTAL:", "Rp 69.300", { bold: true });
await print.writeTextWith2Column("Bayar:", "Rp 100.000");
await print.writeTextWith2Column("Kembali:", "Rp 30.700");
await print.writeLineBreak();
await print.writeText("Terima kasih atas kunjungan Anda!", { align: "center" });
await print.writeText("Follow IG @sadigit.id", { align: "center" });
await print.writeLineBreak({ count: 3 });
updateStatus('✅ Basic receipt printed successfully!', 'success');
}
// 2. Receipt with QR Code
async function printReceiptWithQR(print) {
updateStatus('Printing receipt with QR code...', 'info');
await print.writeText("TOKO SAYA", {
align: "center",
bold: true,
size: "double"
});
await print.writeText("Jl. Contoh No. 123", { align: "center" });
await print.writeText("Telp: 021-12345678", { align: "center" });
await print.writeDashLine();
await print.writeTextWith2Column("No Invoice", "INV-0001");
await print.writeTextWith2Column("Tanggal", "06/10/2024");
await print.writeDashLine();
await print.writeTextWith2Column("Nasi Goreng", "Rp 25.000");
await print.writeTextWith2Column("Es Teh", "Rp 5.000");
await print.writeDashLine();
await print.writeTextWith2Column("TOTAL", "Rp 30.000", {
bold: true,
size: "double"
});
await print.writeDashLine();
await print.writeText("SCAN UNTUK BAYAR", {
align: "center",
bold: true
});
await print.writeLineBreak();
await print.printQRCode("https://example.com/payment/INV-0001/Rp30000", {
size: "large",
align: "center",
errorCorrection: "M"
});
await print.writeLineBreak();
await print.writeText("atau bayar tunai di kasir", { align: "center" });
await print.writeLineBreak({ count: 3 });
updateStatus('✅ Receipt with QR code printed successfully!', 'success');
}
// 3. Receipt with Barcode
async function printReceiptWithBarcode(print) {
updateStatus('Printing receipt with barcode...', 'info');
await print.writeText("INVOICE", {
align: "center",
bold: true,
size: "double"
});
await print.writeDashLine();
await print.writeTextWith2Column("No Invoice", "INV-20241006-001");
await print.writeTextWith2Column("Tanggal", "06/10/2024 15:30");
await print.writeTextWith2Column("Customer", "John Doe");
await print.writeDashLine();
await print.writeText("Items:", { bold: true });
await print.writeTextWith2Column("Product A", "Rp 50.000");
await print.writeTextWith2Column("Product B", "Rp 30.000");
await print.writeTextWith2Column("Product C", "Rp 20.000");
await print.writeDashLine();
await print.writeTextWith2Column("Subtotal", "Rp 100.000");
await print.writeTextWith2Column("Diskon", "- Rp 10.000");
await print.writeTextWith2Column("TOTAL", "Rp 90.000", { bold: true });
await print.writeDashLine();
await print.writeText("Scan barcode untuk tracking:", {
align: "center",
bold: true
});
await print.writeLineBreak();
await print.printBarcode("INV20241006001", {
format: "CODE128",
height: 60,
displayValue: true,
align: "center"
});
await print.writeLineBreak();
await print.writeText("Terima kasih!", { align: "center" });
await print.writeLineBreak({ count: 3 });
updateStatus('✅ Receipt with barcode printed successfully!', 'success');
}
// 4. Complete Demo (All Features)
async function printCompleteDemo(print) {
updateStatus('Printing complete demo with all features...', 'info');
// Header with logo
await print.putImageWithUrl(
"https://www.sadigit.co.id/wp-content/uploads/2021/10/cropped-sadigit-logo.png",
{ align: "center" }
);
await print.writeText("COMPLETE DEMO", {
align: "center",
bold: true,
size: "double"
});
await print.writeText("PrintHub v1.2.1", { align: "center" });
await print.writeDashLine();
// Invoice info
await print.writeTextWith2Column("Invoice No", "DEMO-001");
await print.writeTextWith2Column("Date", "06/10/2024");
await print.writeDashLine();
// Items
await print.writeText("ITEMS:", { bold: true });
await print.writeTextWith2Column("Item Sample 1", "Rp 25.000");
await print.writeTextWith2Column("Item Sample 2", "Rp 15.000");
await print.writeTextWith2Column("Item Sample 3", "Rp 10.000");
await print.writeDashLine();
// Total
await print.writeTextWith2Column("TOTAL", "Rp 50.000", {
bold: true,
size: "double"
});
await print.writeDashLine();
// QR Code
await print.writeText("QRIS PAYMENT", {
align: "center",
bold: true
});
await print.writeLineBreak();
await print.printQRCode("https://qris.online/demo/payment/50000", {
size: "large",
align: "center",
errorCorrection: "M"
});
await print.writeLineBreak();
await print.writeDashLine();
// Barcode
await print.writeText("INVOICE BARCODE", {
align: "center",
bold: true
});
await print.writeLineBreak();
await print.printBarcode("DEMO001", {
format: "CODE128",
height: 60,
displayValue: true,
align: "center"
});
await print.writeLineBreak();
await print.writeDashLine();
// Footer
await print.writeText("Thank You!", {
align: "center",
bold: true,
size: "double"
});
await print.writeText("Visit again!", { align: "center" });
await print.writeLineBreak({ count: 3 });
updateStatus('✅ Complete demo printed successfully!', 'success');
}
// 5. Image Test
async function printImageTest(print) {
updateStatus('Printing image test...', 'info');
await print.writeText("IMAGE TEST", {
align: "center",
bold: true,
size: "double"
});
await print.writeDashLine();
await print.writeText("Left Aligned Image:", { bold: true });
await print.putImageWithUrl(
"https://cdn-icons-png.flaticon.com/256/2504/2504739.png",
{ align: "left" }
);
await print.writeLineBreak();
await print.writeText("Center Aligned Image:", { bold: true });
await print.putImageWithUrl(
"https://cdn-icons-png.flaticon.com/256/2504/2504739.png",
{ align: "center" }
);
await print.writeLineBreak();
await print.writeText("Right Aligned Image:", { bold: true });
await print.putImageWithUrl(
"https://cdn-icons-png.flaticon.com/256/2504/2504739.png",
{ align: "right" }
);
await print.writeLineBreak({ count: 3 });
updateStatus('✅ Image test printed successfully!', 'success');
}
// 6. Text Formatting Test
async function printFormattingTest(print) {
updateStatus('Printing text formatting test...', 'info');
await print.writeText("TEXT FORMATTING TEST", {
align: "center",
bold: true,
size: "double"
});
await print.writeDashLine();
await print.writeText("Normal Text", { align: "left" });
await print.writeText("Bold Text", { align: "left", bold: true });
await print.writeText("Underline Text", { align: "left", underline: true });
await print.writeText("Bold + Underline", { align: "left", bold: true, underline: true });
await print.writeLineBreak();
await print.writeText("Left Aligned", { align: "left" });
await print.writeText("Center Aligned", { align: "center" });
await print.writeText("Right Aligned", { align: "right" });
await print.writeLineBreak();
await print.writeText("Normal Size", { align: "center" });
await print.writeText("Double Size", { align: "center", size: "double" });
await print.writeLineBreak();
await print.writeText("Two Column Test:", { bold: true });
await print.writeTextWith2Column("Item 1", "Rp 10.000");
await print.writeTextWith2Column("Item 2", "Rp 20.000");
await print.writeTextWith2Column("Total", "Rp 30.000", { bold: true });
await print.writeLineBreak();
await print.writeDashLine();
await print.writeText("Line Break Test");
await print.writeLineBreak({ count: 5 });
updateStatus('✅ Text formatting test printed successfully!', 'success');
}
// ===== EVENT LISTENERS =====
function connectAndPrint(printFunction) {
updateStatus('Connecting to printer...', 'warning');
let printer = new PrintHub.init({
paperSize: paperSize,
printerType: printerType,
});
printer.connectToPrint({
onReady: printFunction,
onFailed: (message) => {
updateStatus(`❌ Error: ${message}`, 'error');
console.error('Print error:', message);
}
});
}
document.getElementById('printBasic').addEventListener('click', () => {
connectAndPrint(printBasicReceipt);
});
document.getElementById('printQR').addEventListener('click', () => {
connectAndPrint(printReceiptWithQR);
});
document.getElementById('printBarcode').addEventListener('click', () => {
connectAndPrint(printReceiptWithBarcode);
});
document.getElementById('printComplete').addEventListener('click', () => {
connectAndPrint(printCompleteDemo);
});
document.getElementById('printImage').addEventListener('click', () => {
connectAndPrint(printImageTest);
});
document.getElementById('printFormatting').addEventListener('click', () => {
connectAndPrint(printFormattingTest);
});
</script>
</body>
</html>