Magento – Magento 2 How to add barcode to shipment PDF

barcodemagento2pdfshipment

I want to add barcode of Tracking Number in to my shipment PDF without use of any third party extenssion.

Can any one help me to how to generate barcode in to PDF in magento 2, is there any default magento function to achieve this things.

Any help would be Appreciated! Thanks.

Best Answer

you can use the Zend library Zend_Barcode, see below a cose snippet I have used in the past.

$barcodeConfig = [
                'drawText' => false,
                'barThickWidth'=>'1',
                'barHeight'=>'30',
                'orientation' => 0,
                'text' => $shipment->getTrackingNumber()
            ];
            $rendererConfig = [
                'leftOffset' => $left,
                'topOffset' => $top
            ];
            $renderer = \Zend_Barcode::factory('code128', 'pdf', $barcodeConfig, $rendererConfig)->setResource($this->_getPdf(), 0);
            $renderer->draw();
Related Topic