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.


1 Answer 1


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. Commented Sep 24, 2018 at 4:42
  • How to check if this bar-code value is true or false? Commented Sep 24, 2018 at 5:38
  • See framework.zend.com/manual/2.3/en/modules/… Commented Sep 24, 2018 at 6:08
  • 1
    how to create on magento 2.3 version ?
    – Ashar Riaz
    Commented Dec 11, 2020 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
    Commented Dec 31, 2020 at 8:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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