0

I want to create a svg file with some bar codes inside. So I have tried

<svg width="400" height="202" xmlns="http://www.w3.org/2000/svg"
     xmlns:xlink="http://www.w3.org/1999/xlink">

 <g>
  <title>Layer 1</title>
 </g>

<svg id="barcode1"></svg>
<svg id="barcode2"></svg>
<svg id="barcode3"></svg>
 
<script xlink:href="https://cdn.jsdelivr.net/npm/jsbarcode@3.11.0/dist/barcodes/JsBarcode.code128.min.js"></script>
<script>
JsBarcode("#barcode1", "Hi!");
</script>
</svg>

So I get " Uncaught TypeError: document.createElement(...).getContext is not a function" It doesn't seem to work inside of the svg file, so how can I achieve that?

Murtrag
  • 31
  • 4
  • try using [createElementNS](https://developer.mozilla.org/en-US/docs/Web/API/Document/createElementNS) instead – enxaneta Mar 12 '22 at 07:11
  • What do you mean? You want me to modify condensed JsBarcode file??? – Murtrag Mar 12 '22 at 07:27
  • jsBarcode expects to be in an HTML document. Not an XML document (like an SVG). The code of jsBarcode would need to be modified. You may want to make a feature request to the author. – Paul LeBeau Mar 12 '22 at 08:56

0 Answers0