react-barcode icon indicating copy to clipboard operation
react-barcode copied to clipboard

How to clear the generated barcode in canvas?

Open SyedSaifAli opened this issue 4 years ago • 0 comments

Hi, I have successfully created the canvas. Now, I want to clear this canvas with the click of a button.

<div id="bar_code">
  <Barcode renderer="canvas" value={"test"} font="trebuchet ms" height={50} /><br/>
</div>

on click of button, I am trying the code below,

var bar_cnv = document.getElementById('bar_code').firstChild;
var ctx2 = bar_cnv.getContext('2d');
ctx2.clearRect(0, 0, bar_cnv.width, bar_cnv.height);

But the canvas is not getting cleared. Any help will be appreciated.

SyedSaifAli avatar Mar 10 '21 16:03 SyedSaifAli