-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
254 lines (238 loc) · 10.4 KB
/
index.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
<!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">
<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">
<meta property="og:description"
content="PrintHub is a simple library to print receipt with Bluetooth and USB printer.">
<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">
<meta name="twitter:description"
content="PrintHub is a simple library to print receipt with Bluetooth and USB printer.">
<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="./assets/favicon.ico"
type="image/x-icon">
<link rel="canonical" href="https://defuj.github.io/printhub">
<title>PrintHub</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(/assets/fonts/MerchantCopy.ttf) format('truetype');
}
@font-face {
font-family: 'MerchantCopy';
font-style: normal;
font-weight: 700;
font-display: swap;
src: url(/assets/fonts/MerchantCopyDoublesize.ttf) format('truetype');
}
@font-face {
font-family: 'MerchantCopy';
font-style: normal;
font-weight: 800;
font-display: swap;
src: url(/assets/fonts/MerchantCopyWide.ttf) format('truetype');
}
}
</style>
</head>
<body
class="bg-gray-100 p-4 justify-center items-center w-full flex flex-col">
<div class="bg-white p-4 rounded shadow-md w-[80mm]">
<!-- Print Header -->
<div class="text-center">
<h1 class="text-xl font-bold">SADIGIT</h1>
<p>Jl. Kutamaya No.Ruko A, Kotakulon, Kec. Sumedang Sel.,
Kabupaten Sumedang, Jawa Barat 45311</p>
<p>0852-2299-9699</p>
</div>
<div class="text-center mt-2">
<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>
<div class="flex justify-between">
<span>Item Sample-0</span>
<span>1 pcs x 10.000</span>
</div>
<div class="flex justify-between">
<span>Item Sample-1</span>
<span>1 pcs x 10.000</span>
</div>
<div class="flex justify-between">
<span>Item Sample-2</span>
<span>1 pcs x 10.000</span>
</div>
<div class="flex justify-between">
<span>Item Sample-3</span>
<span>1 pcs x 10.000</span>
</div>
<div class="flex justify-between">
<span>Item Sample-4</span>
<span>1 pcs x 10.000</span>
</div>
</div>
<hr class="my-2 border-t-2 border-dashed">
<!-- Print Total -->
<div class="flex justify-between">
<span>Total :</span>
<span>50.000</span>
</div>
<div class="flex justify-between">
<span>Bayar :</span>
<span>100.000</span>
</div>
<div class="flex justify-between">
<span>Kembali :</span>
<span>50.000</span>
</div>
<div class="flex justify-between">
<span>Metode :</span>
<span>Tunai</span>
</div>
<!-- Print Footer -->
<div class="text-center my-2">
<p>Terimakasih sudah mencoba Follow IG @sadigit.id</p>
</div>
</div>
<div class="flex flex-col space-y-2 mt-4 w-[80mm]">
<!-- select paper size -->
<div class="flex flex-col">
<label for="paperSize">Paper Size:</label>
<select id="paperSize"
class="rounded-lg px-4 py-4 bg-gray-200 text-lg">
<option value="58" selected>58mm</option>
<option value="80">80mm</option>
</select>
</div>
<!-- select printer type -->
<div class="flex flex-col">
<label for="printerType">Printer Type:</label>
<select id="printerType"
class="rounded-lg px-4 py-4 bg-gray-200 text-lg">
<option value="bluetooth" selected>Bluetooth Printer
(Thermal)</option>
<option value="usb">USB Printer (Thermal)</option>
</select>
</div>
<button id="connectToPrinter"
class="rounded-lg px-4 py-2 bg-gray-600 text-white">Print with
Bluetooth Printer</button>
</div>
<p id="status"></p>
<p id="battery"></p>
<script
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/index.global.js"></script>
<script>
let paperSize = '58';
let printerType = 'bluetooth';
document.getElementById('paperSize').addEventListener('change', (e) => {
paperSize = e.target.value;
console.log('Paper Size Changes',paperSize);
});
document.getElementById('printerType').addEventListener('change', (e) => {
printerType = e.target.value;
console.log('Printer Type Changes',printerType);
document.getElementById('connectToPrinter').textContent = `Print with ${printerType === 'bluetooth' ? 'Bluetooth' : 'USB'} Printer`;
});
async function startPrint(print) {
// Print Header
await print.writeText("SADIGIT", {
align: "center",
bold: true,
size: "double",
paperSize: paperSize,
});
await print.writeText(
"Jl. Kutamaya No.Ruko A, Kotakulon, Kec. Sumedang Sel., 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" });
// Print Items
await print.writeDashLine();
for (let i = 0; i < 5; i++) {
await print.writeText("Item Sample-" + i, { align: "left" });
await print.writeTextWith2Column("1 pcs x 10.000", "10.000");
}
await print.writeDashLine();
// Print Total
await print.writeTextWith2Column("Total :", "50.000");
await print.writeTextWith2Column("Bayar :", "100.000");
await print.writeTextWith2Column("Kembali :", "50.000");
await print.writeTextWith2Column("Metode :", "Tunai");
// Print Footer
await print.writeLineBreak();
await print.writeText(
"Terimakasih sudah mencoba Follow IG @sadigit.id",
{ align: "center" }
);
await print.writeLineBreak(3);
}
document.getElementById('connectToPrinter').addEventListener('click', () => {
let printer = new PrintHub.init({
paperSize: paperSize,
printerType: printerType,
});
printer.connectToPrint({
onReady: (print) => startPrint(print),
onFailed: (message) => {
console.log(message);
window.alert(message);
}
});
});
</script>
</body>
</html>