-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathbarcode_test.html
116 lines (92 loc) · 3.95 KB
/
barcode_test.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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PDF417 - 2D Barcode generator test</title>
<script src="bcmath-min.js" type="text/javascript"></script>
<script src="pdf417-min.js" type="text/javascript"></script>
<script>
window.onload = function() {
var hub3_code = "HRVHUB30\nHRK\n" +
"000000000012355\n"+
"ZELJKO SENEKOVIC\n"+
"IVANECKA ULICA 125\n"+
"42000 VARAZDIN\n"+
"2DBK d.d.\n"+
"ALKARSKI PROLAZ 13B\n"+
"21230 SINJ\n"+
"HR1210010051863000160\n"+
"HR01\n"+
"7269-68949637676-00019\n"+
"COST\n"+
"Troskovi za 1. mjesec\n";
var textToEncode = document.getElementById("textToEncode");
textToEncode.value = hub3_code;
PDF417.init(hub3_code);
var barcode = PDF417.getBarcodeArray();
// block sizes (width and height) in pixels
var bw = 2;
var bh = 2;
// create canvas element based on number of columns and rows in barcode
var canvas = document.createElement('canvas');
canvas.width = bw * barcode['num_cols'];
canvas.height = bh * barcode['num_rows'];
document.getElementById('barcode').appendChild(canvas);
var ctx = canvas.getContext('2d');
// graph barcode elements
var y = 0;
// for each row
for (var r = 0; r < barcode['num_rows']; ++r) {
var x = 0;
// for each column
for (var c = 0; c < barcode['num_cols']; ++c) {
if (barcode['bcode'][r][c] == 1) {
ctx.fillRect(x, y, bw, bh);
}
x += bw;
}
y += bh;
}
}
function generate() {
var textToEncode = document.getElementById("textToEncode");
PDF417.init(textToEncode.value);
var barcode = PDF417.getBarcodeArray();
// block sizes (width and height) in pixels
var bw = 2;
var bh = 2;
// create canvas element based on number of columns and rows in barcode
var container = document.getElementById('barcode');
container.removeChild(container.firstChild);
var canvas = document.createElement('canvas');
canvas.width = bw * barcode['num_cols'];
canvas.height = bh * barcode['num_rows'];
container.appendChild(canvas);
var ctx = canvas.getContext('2d');
// graph barcode elements
var y = 0;
// for each row
for (var r = 0; r < barcode['num_rows']; ++r) {
var x = 0;
// for each column
for (var c = 0; c < barcode['num_cols']; ++c) {
if (barcode['bcode'][r][c] == 1) {
ctx.fillRect(x, y, bw, bh);
}
x += bw;
}
y += bh;
}
}
</script>
</head>
<body>
<p>Text to encode</p>
<textarea id="textToEncode" style="width: 100%; height: 200px;"></textarea>
<p><button onclick="generate()">Generate</button></p>
<p>PDF417 2D barcode in canvas</p>
<div id="barcode"></div>
<p>(test using your mobile phone barcode scanner or right click on the barcode image and save as image file,
then decode using <a href="https://zxing.org/w/decode.jspx">https://zxing.org/w/decode.jspx</a>)</p>
</body>
</html>