I want to make a button to print a generated barcode as an svg or as an png
HTML code:
<input class="form-control" type="text" placeholder="put the code here">
<svg class="hidden" id="barcode" onclick="window.print(this)" id="svgObject" width="100" height="100"></svg>
<button class="btn btn-outline-danger">Generate</button>
<input class="btn btn-outline-danger" type="button" onclick="printDiv('print-content')" value="print"/>
</section>
<script src="jsBarcode.code128.min.js"></script>
<script src="index.js"></script>
js code:
document.querySelector("button").addEventListener("click" , function() {
var text = document.querySelector("input").value;
JsBarcode("#barcode", text);
document.getElementById("barcode").classList.remove("hidden")
});
function printDiv(divName) {
var printContents = document.getElementById(barcode).outerHTML;
w=window.open();
w.document.write(printContents);
w.print();
w.close();
}
I am using this js generator :https://lindell.me/JsBarcode/
when is use this code It prints it as a pdf not an SVG or any image format