-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
65 lines (61 loc) · 2.76 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
<!DOCTYPE HTML>
<html>
<head>
<title>Printing Labels with b-Pac 🖨</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" type="image/ico" href="favicon.ico" />
<link href="https://fonts.googleapis.com/css2?family=Roboto&display=swap" rel="stylesheet">
<link href="styles.css" rel="stylesheet">
<script type="module">
import * as bpac from '/assets/js/bpac.js';
const MODEL_FILE = "C:\\Users\\mp182\\Desktop\\label.lbx";
window.Print = async function DoPrint() {
if (bpac.IsExtensionInstalled() == false) {
const agent = window.navigator.userAgent.toLowerCase();
const ischrome = (agent.indexOf('chrome') !== -1) && (agent.indexOf('edge') === -1) && (agent.indexOf('opr') === -1)
if (ischrome) {
window.alert('You need the b-Pac extension, in the next window you can install it.');
window.open('https://chrome.google.com/webstore/detail/ilpghlfadkjifilabejhhijpfphfcfhb', '_blank');
}
else {
window.alert('This feature is only enabled for Google Chrome.');
}
return;
} else {
const bPacDoc = bpac.IDocument;
const modelFileExist = await bPacDoc.Open(MODEL_FILE);
if (modelFileExist != false) {
try {
const form = document.getElementById("bpacForm");
const productName = await bPacDoc.GetObject("productName");
const qrCode = await bPacDoc.GetObject("qrCode");
productName.Text = form.product.value;
qrCode.Text = "https://www.google.com/search?q=" + form.product.value;
bPacDoc.StartPrint("", 0);
bPacDoc.PrintOut(1, 0);
bPacDoc.EndPrint();
bPacDoc.Close();
}
catch (e) {
console.log(e);
window.alert('Unable to print the label, try again later.');
}
} else {
window.alert('The model file of the label is not accessible.');
}
}
}
</script>
</head>
<body>
<h1>Printing Labels with b-Pac 🖨</h1>
<div>
<form id="bpacForm" action="javascript:Print();">
<label>Product: </label>
<input type="text" id="product" name="product" value="" maxlength="10" required>
<button type="submit">Print 🖨</button>
</form>
</div>
</body>
</html>