lindell / JsBarcode

Barcode generation library written in JavaScript that works in both the browser and on Node.js
http://lindell.me/JsBarcode
MIT License
5.49k stars 1.11k forks source link

margin take in account only the first time #326

Open ikit opened 4 years ago

ikit commented 4 years ago

Hi,

I'm stuck with a weird problem... I think it's a bug of the library.

I'm using jsBarcode to generate product labels

<div id="productLabel" >
    <p>TAG {{ product.tagNumber }}</p>
    <img id="barcode1" />

    <p>PNR {{ product.material.uid }}</p>
    <img id="barcode2" />

    <p>SER {{ product.serialNumber }}</p>
    <img id="barcode3" />
  </div>
    JsBarcode(document.getElementById("barcode1"))
      .CODE128(`*RPO ${product.uid}*`,  { height: 50, displayValue: false, margin: 0 })
      .render();

    JsBarcode(document.getElementById("barcode2"))
      .CODE128(`*PNR ${product.material.uid}*`, { height: 50, displayValue: false, margin: 0 })
      .render();

    JsBarcode(document.getElementById("barcode3"))
      .CODE128(`*SER ${product.serialNumber}*`, { height: 50, displayValue: false, margin: 0 })
      .render();

Only the first generated barcode will have no margin Other barcode will have default margin (10px)

If I switch the order, by example i generate the #barcode2 before the #barcode1, the #barcode2 will have no margin, and the 1 and 3 will have default margin...

lindell commented 4 years ago

This does indeed seem to be a bug. Will look into it. https://jsfiddle.net/6b5j78va/1/