Skip to content

Commit 9c36b79

Browse files
committed
Use bwipjs barcode generator service for previewing barcodes, qrcodes and pdf417
1 parent 71703d3 commit 9c36b79

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

tools/playground.html

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,15 +340,36 @@
340340
}
341341

342342
if (command.type === 'qrcode' && command.command === 'print') {
343-
result += `<div class='placeholder ${command.type} ${align}'><div>qrcode</div></div>`;
343+
result += `<div class='placeholder ${command.type} ${align}'><img src='http://bwipjs-api.metafloor.com/?bcid=qrcode&text=${command.value}' onerror="this.style.display='none'"></div>`;
344344
}
345345

346346
if (command.type === 'pdf417' && command.command === 'print') {
347-
result += `<div class='placeholder ${command.type} ${align}'><div>pdf417</div></div>`;
347+
result += `<div class='placeholder ${command.type} ${align}'><img src='http://bwipjs-api.metafloor.com/?bcid=pdf417&text=${command.value}' onerror="this.style.display='none'"></div>`;
348348
}
349349

350350
if (command.type === 'barcode' && ! command.property) {
351-
result += `<div class='placeholder ${command.type} ${align}'><div>barcode</div></div>`;
351+
let symbologies = {
352+
'upca': 'upca',
353+
'upce': 'upce',
354+
'ean13': 'ean13',
355+
'ean8': 'ean8',
356+
'code39': 'code39',
357+
'coda39': 'code39',
358+
'itf': 'interleaved2of5',
359+
'interleaved-2-of-5': 'interleaved2of5',
360+
'nw-7': 'rationalizedCodabar',
361+
'codabar': 'rationalizedCodabar',
362+
'code93': 'code93',
363+
'code128': 'code128',
364+
'gs1-128': 'gs1-128',
365+
'gs1-databar-omni': 'databaromni',
366+
'gs1-databar-truncated': 'databartruncated',
367+
'gs1-databar-limited': 'databarlimited',
368+
'gs1-databar-expanded': 'databarexpanded',
369+
'code128-auto': 'code128',
370+
}
371+
372+
result += `<div class='placeholder ${command.type} ${align}'><img src='http://bwipjs-api.metafloor.com/?bcid=${symbologies[command.value.symbology]}&text=${command.value.data}' onerror="this.style.display='none'"></div>`;
352373
}
353374

354375
if (command.type === 'image') {
@@ -795,6 +816,8 @@
795816
}
796817
#output[data-format="text"] .placeholder * {
797818
display: block;
819+
width: calc(var(--width-a) * 24);
820+
height: calc(var(--height-a) * 4);
798821
}
799822
#output[data-format="text"] .placeholder div {
800823
background: #ddd;

0 commit comments

Comments
 (0)