-
Notifications
You must be signed in to change notification settings - Fork 28
/
index.html
292 lines (283 loc) · 10.5 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>QR Code Label Generator for ASN in Paperless-ngx</title>
<link
rel="canonical"
href="https://tobiasmaier.info/asn-qr-code-label-generator/"
/>
<script src="https://cdn.tailwindcss.com?plugins=forms,typography"></script>
<script
src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js"
defer
></script>
<style>
@media print {
/* See https://caniuse.com/css-paged-media */
@page {
/* Remove default margin set by the browser */
margin: 0mm;
size: A4;
}
}
</style>
</head>
<body class="print:p-0" x-data="qrCodeApp()">
<div class="container mx-auto print:hidden">
<h1 class="mb-4 text-xl font-bold print:hidden">
QR Code Label Generator for
<abbr title="Archive Serial Number">ASN</abbr> in Paperless-ngx
</h1>
<div
class="prose prose-a:text-blue-600 prose-a:underline hover:prose-a:text-blue-700 mb-4 print:hidden"
>
<p>
This tool generates QR code labels for the
<a
href="https://docs.paperless-ngx.com/advanced_usage/#archive-serial-number-assignment"
>Archive Serial Number (ASN)</a
>
feature in
<a href="https://docs.paperless-ngx.com/">Paperless-ngx</a>.
</p>
<p>
The <abbr title="Archive Serial Number">ASN</abbr> feature allows you
to assign a unique serial number to each document in your archive.
This is useful if you want to refer to a document in a paperless
workflow. For example, you can print the
<abbr title="Archive Serial Number">ASN</abbr>
on a document and then use it to search for the document in
Paperless-ngx.
</p>
<p>
This tool generates QR code labels for the
<abbr title="Archive Serial Number">ASN</abbr> feature. You can
generate labels for up to 189 documents at once. The labels are
formatted to <strong>fit on Avery L4731REV-25 labels</strong>.
</p>
<p>
To use this tool, enter the start number, prefix, and number of
leading zeros. Then click the "Regenerate Labels" button. The labels
will be generated and displayed below. You can then print the labels
by clicking the "Print Labels" button.
</p>
<p>
One <strong>known limitation of this tool</strong> is that it
<strong>only works on Google Chrome and possibly Firefox</strong>.
This is because it uses the
<a href="https://caniuse.com/css-paged-media"><code>@page</code></a>
CSS rule to control the page size, margin, and to turn off the default
header and footer of the browser.
</p>
</div>
<form @submit.prevent="generateLabels()" class="mb-8 print:hidden">
<!-- User Input Fields -->
<div class="mb-5 grid grid-cols-1 gap-5 md:grid-cols-2">
<div>
<label
for="startNumber"
class="mb-2 block text-sm font-medium text-gray-900"
>Start Number</label
>
<input
type="number"
id="startNumber"
x-model="startNumber"
required
min="1"
step="1"
value="1"
class="block w-full rounded-lg border border-gray-300 bg-gray-50 p-2.5 text-sm text-gray-900 focus:border-blue-500 focus:ring-blue-500"
/>
<div class="mt-1">
<p
class="prose prose-sm prose-a:text-blue-600 prose-a:underline hover:prose-a:text-blue-700 max-w-none"
>
The number of labels generated will be 7 x 27 = 189. This means
the <strong>next batch</strong> of labels should
<strong
>start with
<span x-text="parseInt(startNumber, 10) + 189"
>190</span
></strong
>.
</p>
</div>
</div>
<div>
<label
for="prefix"
class="mb-2 block text-sm font-medium text-gray-900"
>Prefix</label
>
<input
type="text"
id="prefix"
x-model="prefix"
required
value="ASN"
class="block w-full rounded-lg border border-gray-300 bg-gray-50 p-2.5 text-sm text-gray-900 focus:border-blue-500 focus:ring-blue-500"
/>
<div class="mt-1">
<p
class="prose prose-sm prose-a:text-blue-600 prose-a:underline hover:prose-a:text-blue-700 max-w-none"
>
If you change this, <strong>update the prefix</strong> in
Paperless-ngx accordingly via
<a
href="https://docs.paperless-ngx.com/configuration/#PAPERLESS_CONSUMER_ASN_BARCODE_PREFIX"
><code>PAPERLESS_CONSUMER_ASN_BARCODE_PREFIX</code></a
>.
</p>
</div>
</div>
<div>
<label
for="leadingZeros"
class="mb-2 block text-sm font-medium text-gray-900"
>Number of Leading Zeros</label
>
<input
type="number"
id="leadingZeros"
x-model="leadingZeros"
required
value="5"
min="0"
class="block w-full rounded-lg border border-gray-300 bg-gray-50 p-2.5 text-sm text-gray-900 focus:border-blue-500 focus:ring-blue-500"
/>
</div>
<div>
<div class="flex items-start">
<div class="flex h-5 items-center">
<input
type="checkbox"
id="borderToggle"
x-model="borderToggle"
class="focus:ring-3 h-4 w-4 rounded border border-gray-300 bg-gray-50 focus:ring-blue-300"
/>
</div>
<label
for="borderToggle"
class="ms-2 text-sm font-medium text-gray-900"
>Show Border</label
>
</div>
<div class="mt-1">
<p
class="prose prose-sm prose-a:text-blue-600 prose-a:underline hover:prose-a:text-blue-700 max-w-none"
>
This may be useful for debugging or to calibrate the print out.
</p>
</div>
</div>
</div>
<button
@click.prevent="generateLabels()"
class="w-full rounded-lg bg-blue-700 px-5 py-2.5 text-center text-sm font-medium text-white hover:bg-blue-800 focus:outline-none focus:ring-4 focus:ring-blue-300 sm:w-auto"
>
Regenerate Labels
</button>
<button
@click.prevent="printLabels()"
class="w-full rounded-lg bg-blue-700 px-5 py-2.5 text-center text-sm font-medium text-white hover:bg-blue-800 focus:outline-none focus:ring-4 focus:ring-blue-300 sm:w-auto"
>
Print Labels
</button>
</form>
</div>
<div
class="container mx-auto w-[210mm] border px-[8.45mm] py-[13.5mm] print:w-full print:max-w-full print:border-0"
>
<!-- Display QR Code Labels -->
<ol class="grid grid-cols-7 gap-x-[2.55mm]">
<template x-for="label in labels">
<li class="h-[10mm] w-[25.4mm]">
<div
class="flex h-[9mm] w-[24.4mm] items-center border-[0.5mm] odd:border-blue-500 even:border-red-300"
:class="{'even:border-transparent odd:border-transparent': !borderToggle}"
>
<img
:src="label.qrCodeUrl"
alt=""
width="100"
height="100"
class="mr-[0.5mm] aspect-square h-[9mm] w-[9mm] flex-none"
referrerpolicy="no-referrer"
/>
<div
class="flex-grow"
:class="{
'text-[3.9mm]': label.text.length <= 6,
'text-[3.2mm]': label.text.length == 7,
'text-[2.7mm]': label.text.length == 8,
'text-[2.4mm]': label.text.length == 9,
'text-[2.1mm]': label.text.length >= 10,
}"
x-text="label.text"
></div>
</div>
</li>
</template>
</ol>
</div>
<footer class="mt-8 bg-gray-200 py-4 text-center print:hidden">
<p>
© 2023
<a
href="https://tobiasmaier.info"
class="text-blue-600 underline hover:text-blue-700"
>Tobias L. Maier</a
>. All rights reserved. Licensed under the
<a
href="https://www.gnu.org/licenses/agpl-3.0.html"
title="GNU Affero General Public License"
class="text-blue-600 underline hover:text-blue-700"
>AGPL v3.0</a
>.
<a
href="https://github.com/tmaier/asn-qr-code-label-generator"
class="text-blue-600 underline hover:text-blue-700"
>Contribute via GitHub</a
>
</p>
</footer>
<script>
function qrCodeApp() {
return {
startNumber: 1,
prefix: "ASN",
leadingZeros: 4,
borderToggle: false,
labels: [],
generateLabels() {
this.labels = [];
let totalLabels = 7 * 27; // 7 columns x 27 rows
let startNumberInt = parseInt(this.startNumber, 10); // Ensure startNumber is an integer
let leadingZerosInt = parseInt(this.leadingZeros, 10); // Ensure leadingZeros is an integer
for (let i = 0; i < totalLabels; i++) {
let number = startNumberInt + i;
let paddedNumber = number
.toString()
.padStart(leadingZerosInt + 1, "0");
let text = this.prefix + paddedNumber;
// See https://goqr.me/api/doc/create-qr-code/
let qrCodeUrl = `https://api.qrserver.com/v1/create-qr-code/?size=300x300&data=${encodeURIComponent(
text
)}`;
this.labels.push({ qrCodeUrl, text });
}
},
printLabels() {
window.print();
},
init() {
this.generateLabels();
},
};
}
</script>
</body>
</html>