How To Print Sticker/barcode Label Directly From Browser On A (Zebra) Printer

I have generated barcode image in php but I need to print it in label sticker from zebra printer, so setting to be done to print in label paper.

While running below code whole page is getting printed instead of only barcode image, any suggestion?

how to set up page for label printing?




<div id="print">

<img  src="images/barCode.png" alt="" style="display: block;">

</div>

<script type="text/javascript">

    window.onload = function() {

        window.print();

        setTimeout(function() {

            window.close();

        }, 1);

    };

    

</script>



Printing directly from browser sucks. I’ve tried all kind of things, but only if you can approach the printer directly it never worked flawless for me.

My solution was to create a PDF file, put it on a place the printer could access to and then send a command to print that file.

And for a label printer. Create a TXT file and put it on a default place the label printer can access. Then run some kind of script that triggers the label printer.

Long time ago, can’t give you the details.