If you want to add a barcode in your Invoice or shipment PDF file in Magento, you might find this post helpful.
Please follow the steps below:
First off, create a folder in your magento media directory where the barcode will be saved as below:
MAGENTO_ROOT/media/Directory_Name
– I created ‘invoicebarcode’ directory and set that directory in a variable ‘$dir_invoicebarcode’
Second off or Final Step, add the code below into your Invoice.php file
/* 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*/
To add barcode in the Shipment PDF file please follow the same steps and I look forward to receiving your comments.