Magento – How to add Barcode in invoice pdf in magento

invoicemagento-1.9pdf

I want to print "Barcode"(image) in invoice means when we generate invoice from admin panel the that invoice should contain all product related details along with barcode image .I saw all questions related to above problem but i did't satisfy.

Please tell me step by step instruction where we have to modify files (file path) for adding barcode attribute to pdf.

Best Answer

We implemented a barcode on the PDF in FireGento_Pdf. In this case, the barcode represents the order number. But you could have a look at the code to see how it is done here. The main part is this:

$barcodeConfig = array(
    'drawText' => false,
    'orientation' => 90,
    'text' => $order->getIncrementId()
);
$rendererConfig = array(
    'verticalPosition' => 'middle',
    'moduleSize' => 0.9
);
// create dummy Zend_Pdf object, which just stores the current page, so that we can pass it in
// Zend_Barcode_Renderer_Pdf->setResource()
$pdf = new Zend_Pdf();
$pdf->pages[] = $page;
/** @var $renderer Zend_Barcode_Renderer_Pdf */
$renderer = Zend_Barcode::factory('code128', 'pdf', $barcodeConfig, $rendererConfig)->setResource($pdf, 0);
// calculate left offset so that barcode is printed on the right with a little margin
$leftOffset = $page->getWidth() - $renderer->getBarcode()->getWidth(true) * $renderer->getModuleSize() - 10;
$renderer->setLeftOffset($leftOffset);
$renderer->draw();
Related Topic