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.


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

$barcodeConfig = [
                'drawText' => false,
                'orientation' => 0,
                'text' => $shipment->getTrackingNumber()
            $rendererConfig = [
                'leftOffset' => $left,
                'topOffset' => $top
            $renderer = \Zend_Barcode::factory('code128', 'pdf', $barcodeConfig, $rendererConfig)->setResource($this->_getPdf(), 0);
  • when i scan barcode it is display value code128 not display tracking number. Sep 24 '18 at 4:42
  • How to check if this bar-code value is true or false? Sep 24 '18 at 5:38
  • 1
    how to create on magento 2.3 version ?
    – Ashar Riaz
    Dec 11 '20 at 14:48
  • I don't believe this works on any Magento 2 version as Zend_Barcode is not a anymore available within the ootb libraries
    – laurent
    Dec 31 '20 at 8:39

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.