Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

PhoeniX5's avatar

How to print milon barcode in Laravel ?

Hello, I use the milon package to generate barcodes in laravel, the generated barcode is displayed in the whole view, I need to print these barcodes in small tickets like BarTender templates.

Screenshot :

https://imgur.com/a/3t3gKyo

0 likes
3 replies
tisuchi's avatar

@phoenix5

The package itself explained clearly how to do that. For example, to print it out-

echo DNS1D::getBarcodeSVG("4445645656", "PHARMA2T");
echo DNS1D::getBarcodeHTML("4445645656", "PHARMA2T");
echo '<img src="data:image/png,' . DNS1D::getBarcodePNG("4", "C39+") . '" alt="barcode"   />';
echo DNS1D::getBarcodePNGPath("4445645656", "PHARMA2T");
echo '<img src="data:image/png;base64,' . DNS1D::getBarcodePNG("4", "C39+") . '" alt="barcode"   />';

If you want to change width and height, here is the solution-

echo DNS1D::getBarcodeSVG("4445645656", "PHARMA2T",3,33);
echo DNS1D::getBarcodeHTML("4445645656", "PHARMA2T",3,33);
echo '<img src="' . DNS1D::getBarcodePNG("4", "C39+",3,33) . '" alt="barcode"   />';
echo DNS1D::getBarcodePNGPath("4445645656", "PHARMA2T",3,33);
echo '<img src="data:image/png;base64,' . DNS1D::getBarcodePNG("4", "C39+",3,33) . '" alt="barcode"   />';

Check more: https://github.com/milon/barcode

PhoeniX5's avatar

@tisuchi thank you for your reply, I tried the code you posted :

View :

<body>
    <div class="row">
        <?php echo DNS1D::getBarcodeSVG("4445645656", "PHARMA2T",3,33);
            echo DNS1D::getBarcodeHTML("4445645656", "PHARMA2T",3,33);
            echo '<img src="' . DNS1D::getBarcodePNG("4", "C39+",3,33) . '" alt="barcode"   />';
            echo DNS1D::getBarcodePNGPath("4445645656", "PHARMA2T",3,33);
            echo '<img src="data:image/png;base64,' . DNS1D::getBarcodePNG("4", "C39+",3,33) . '" alt="barcode"   />';
            ?>
    </div>
</body>

I get this :

https://imgur.com/a/gkPB0eZ

This is supposed to generate a png of the barcode that can be printed, I dont understand why it's not working ?

brijeshmkt's avatar

Getting the same issues. It was working fine previously when I was using ip. But when using domain it's giving issue like yours.

I completed the project locally. After that, I uploaded the code to the VPS server. I checked the code using vps ip address and all was working well.

After that I mapped the domain with the ip, then when I checked the system using the domain name, I started getting error like yours.

I guess the error is something related to the path. Hope this helps you in further debugging.

Please or to participate in this conversation.