Recently I was allocated to a project which requires generating EAN-13 barcode. I didn't have experience in barcode generation previously. So I did a research in Internet. If you search in Google it gives you plenty of answers, but the problem I had was I wanted an "EAN-13" barcode generating library in PHP which is under LGPL license. Out of the solutions I found, below is the library that worked for me without any issues.
Library: TCPDF
- This library supports both PDF & barcode generation.
- This has nice & simple examples in it. For barcode generation, check under "Barcodes" section.
Steps I followed to generate an EAN 13 barcode
- Downloaded the tcpdf_6_2_4.zip (16.7 MB) & extracted it.
- Copied the extracted "tcpdf" folder to my web root directory (eg. /var/www/tcpdf)
- Opened the project in IDE (eg. Netbeans)
- Opened /var/www/tcpdf/tcpdf/examples/barcodes/example_1d_html.php & replaced 'http://www.tcpdf.org' by my preferred EAN 13 barcode ("1234567890128", Note: Make sure you give a valid EAN 13 barcode number)
- Necessary code snippet <?php
- Accessed the php file from the browser (eg. http://localhost/tcpdf/tcpdf/examples/barcodes/example_1d_html.php)
// include 1D barcode class (search for installation path)
require_once(dirname(__FILE__).'/tcpdf_barcodes_1d_include.php');
// set the barcode content and type
$barcodeobj = new TCPDFBarcode("1234567890128", 'EAN13');
// output the barcode as HTML object
echo $barcodeobj->getBarcodeHTML(2, 30, 'black');
?>
It nicely displays the barcode. I even read it using a barcode reader using an android phone application.
Note that it doesn't display the barcode number below the barcode content. If you need to display it, you could either use this example or you will have to extend the existing code & write the logic.
So, that's it! & I hope this helps :)
Feel free to share the blog post if you find it interesting & helpful for others...
PS: Coming up next post... "PHP: send multiple events to MS Outlook 2010 calendar through one email"
Though I didn't understand half the things; I thought it looked amazingly fluent in tech jargon yet simply-written for developers to understand (According to my little knowledge)
ReplyDeleteWell-done Hasarangi,I am very proud of you. Few writing elements that need to be brush-up but I am 200% sure you will get it right.Happy Blogging :-)
Thank you කොම්පීතරයා!! I'm glad to receive a nice comment from an experienced blogger like you :)
Delete