If you want to add a barcode in your Invoice or shipment PDF in Magento, this blog will help you to do that. It’s very easy to implement. If you have some Magento developing skill, you can do it easily. I tested with different Magento versions and it’s working fine.

screen_shot_03_1

Follow bellow steps:

First Step, create a folder in your magento media directory where barcode will save like below:

MAGENTO_ROOT/media/Directory_Name

– I created ‘invoicebarcode’ directory and set that directory in a variable ‘$dir_invoicebarcode’

Second or Final Step, add the below code into your Invoice.php

/* Start Barcode */
$dir_invoicebarcode = "invoicebarcode";
$barCodeNo = $invoice->getIncrementId(); //For Order Number add this: $order->getIncrementId()
 
header('Content-Type: image/png');
$barcodeOptions = array('text' => $barCodeNo, 'barHeight'=> 30, 'factor'=>1,);
$rendererOptions = array();
$imageResource = Zend_Barcode::draw(
 'code39', 'image', $barcodeOptions, $rendererOptions
);
$upload_path = str_replace("\\/","/",Mage::getBaseDir('media').DS.$dir_invoicebarcode.DS.$barCodeNo."_barcode.png");
chmod($upload_path,0777);
imagepng($imageResource,$upload_path, 0, NULL);
imagedestroy($imageResource);
 
$barcode_image = $upload_path;
$barcode_y = $this->y;
if (is_file($barcode_image)) {
 $barcode_image = Zend_Pdf_Image::imageWithPath($barcode_image);
    $page->drawImage($barcode_image, 440, $barcode_y-30, 550, $barcode_y);
}
/* End Barcode*/

I hope my blog will help you. Also maintain this code structure you can add barcode in Shipment PDF.

Please let me know if you have any question by comment.

2 thoughts on “Barcode in Invoice/shipment PDF in Magento

Comments are closed.