Search code examples
phpbarcodetcpdf

How to save TCPDF png barcode to a specified folder in php?


I can generate a barcode using TCPDF using the following code:

$barcodeobj = new TCPDF2DBarcode('http://www.tcpdf.org', 'QRCODE,L');
$barcodeobj->getBarcodePNG(6, 6, array(0,0,0));

Instead of displaying the barcode on screen I just want to save the png barcode to a specified folder, I checked through the documentation but couldn't find how to achieve that. (I understand how to save a generated PDF).

Any help achieving that would be appreciated.

Thanks


Solution

  • Easy :

    Instead of

    $barcodeobj->getBarcodePNG(6, 6, array(0,0,0));
    

    Use :

    $file_png = "Pictures/barcode.png";
    file_put_contents($file_png, $barcodeobj->getBarcodePngData());
    

    That's all.