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

zigma's avatar
Level 1

Problem displaying barcode using milon/barcode with domPDF

I'm having problem displaying barcode using milon/barcode with domPDF

If i try to output it in html with the following code it works properly.:

laravel controller file //where dataproduct is array of product.id, product.name and etc

    return view('produk.barcode',compact('dataproduct','no'));

html:

    <img src="data::image/png;base64,{{ DNS1D::getBarcodePNG($data->code_product,'C39') }}" height="60" width="180" /><br />

when I try to output it with dompdf with the following code, the barcode doesn't show up properly. it gives "image not found or type unknown" error message

laravel controller file //where dataproduct is array of product.id, product.name and etc

    $pdf = PDF::setOptions(['isHtml5ParserEnabled'=>true,'isRemoteEnabled'=>true])->loadView('product.barcode',compact('dataproduct','no'));
    $pdf->setPaper('a4', 'potrait');
    return $pdf->stream();

html:

    <img src="data::image/png;base64,{{ DNS1D::getBarcodePNG($data->code_product,'C39') }}" height="60" width="180" /><br />

it seems that dompdf can't display the png image i generated on fly. Can anyone help me with this problem?

thanks

0 likes
2 replies
s4muel's avatar
s4muel
Best Answer
Level 50

give this a shot. i replaced :: with :

<img src="data:image/png;base64,{{ DNS1D::getBarcodePNG($data->code_product,'C39') }}" height="60" width="180" /><br />
1 like
zigma's avatar
Level 1

Woah it works!

All this time I thought it requires ::

Thank u !

1 like

Please or to participate in this conversation.