In present scenario E-Commerce is playing a very essential role in the online business. It’s one of the best & cheapest intermediate for reaching out to new customers in the online market, if it’s implemented effectively. Every business house wants to maximize more within limited time span.
One can maximize profit in online business only when things are automated which reduce human effort and time too.
Seeing the present scenario barcode is gaining popularity. Now the question arises why barcode is gaining popularity? It’s simply because it can be send to any system just by scanning.
As we know that we can generate a pdf of any order shipment in magento. So today we will learn about creating as well as printing a barcode of order shipping number on shipment pdf.

To start with… we need barcode font so one must have to download barcode font.

Then we need to collect the shipping code of that order. Using below function we can create a bar code image of concerned shipping code and then we need to save that image in a folder for printing the bar code in pdf.

Below are the step which will guide you through the process.

Step 1: Open file app/code/core/Mage/Sales/Model/Order/Pdf/Abstract.php

Step 2: Find “function insertOrder”.

Step 3: At the end of the function add the bottom code.

$orderId = Mage::getModel('sales/order')->loadByIncrementId($order->getRealOrderId());
$shipmentCollection = Mage::getResourceModel('sales/order_shipment_collection')->setOrderFilter($orderId)->load();
foreach ($shipmentCollection as $shipment){
 foreach ($shipment->getAllTracks() as $tracking){
 $number = $tracking->getTrackNumber();
 $imgPath = 'barcode/images/'.$number.'.png';
 $barcode_font = 'barcode/font/FREE3OF9.TTF';
 $width = 340;
 $height = 70;
 $img = imagecreate($width, $height);
 $white = imagecolorallocate($img, 255, 255, 255);
 $black = imagecolorallocate($img, 0, 0, 0);
 imagettftext($img, 52, 0, 10, 60, $black, $barcode_font, $number);
 header('Content-type: image/png');
 imagepng($img, $imgPath);  

 $barcodeImage = Zend_Pdf_Image::imageWithPath($imgPath);
 $page->drawImage($barcodeImage, 390, 755, 560, 790);

 $page->setFillColor(new Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92));

 $shipCoText = $tracking->getTitle();
 $shipCoFont = $this->_setFontBold($page, 10);
 $page->drawText($shipCoText, $this->getAlignRight($shipCoText, 400, 170, $shipCoFont, 15), 792, 'UTF-8'); 

 $tracNoText = 'Tracking number : '.$tracking->getTrackNumber(); ;
 $tracNoFont = $this->_setFontRegular($page, 10);
 $page->drawText($tracNoText, $this->getAlignRight($tracNoText, 300, 270, $tracNoFont, 11), 747, 'UTF-8');

Remember “$imgPath” was the image path of the barcode and “$barcode_font” was the barcode font path.

Step 4: Print a shipment from magento admin.

It will be better if you override the function “insertOrder” from core folder.