1

How to create Barcode in invoice can any one suggest barcode in invoice

2

You need to install image library for this. and add following code in your invoice.php

Override the invoice.php

app\code\local\Mage\Sales\Model\Order\Pdf\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 = $page->getHeight()- 30 ;
                if (is_file($barcode_image)) {
                 $barcode_image = Zend_Pdf_Image::imageWithPath($barcode_image);
                    $page->drawImage($barcode_image, 240, $barcode_y - 30, 350, $barcode_y);
                }
                /* End Barcode*/    
  • under which method i need to add i didn't see any barcode after adding this in my pdf – user31402 Apr 5 '16 at 17:28
  • Hi you need to add this in public function getPdf($invoices = array()) methis – Ajay Patel Apr 6 '16 at 11:30
  • Please create folder under the media folder like this app/media/invoicebarcode. after that please comment the header('Content-Type: image/png'); line from the above code. and set relative positive here drawImage($barcode_image, 240, $barcode_y - 30, 350, $barcode_y); based on your PDF – Ajay Patel Apr 6 '16 at 11:56
  • No i am not getting same only – user31402 Apr 7 '16 at 10:38
  • sorry?? i cant understand – Ajay Patel Apr 7 '16 at 10:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy