Rickin Rathatha
Rickin Rathatha

Reputation: 187

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

Upvotes: 3

Views: 2928

Answers (2)

Manish Pareek
Manish Pareek

Reputation: 407

Important note about TCPDF library:

A new version of this library is under development at https://github.com/tecnickcom/tc-lib-pdf and as a consequence this version will not receive any additional development or support. This version should be considered obsolete, new projects should use the new version as soon it will become stable.

For generating linear and bidimensional barcodes there is separate library: https://github.com/tecnickcom/tc-lib-barcode

To save barcode as image using the tc-lib-barcode library:

$bobj = $barcode->getBarcodeObj('CODABAR', '123456', -3, -30, 'black', array(0, 0, 0, 0));
$destination_folder = "uploads/barcode.png";
file_put_contents($destination_folder, $bobj->getPngData());

Upvotes: 1

Jerry
Jerry

Reputation: 1238

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.

Upvotes: 2

Related Questions