How to Create Barcode and Add it in Magento 2 Invoice PDF

Magento 2 allows the admin to send invoice PDF as the order completes.

Invoices are the official documents that you send with every order that is important for accounting and tax purposes.

The default Magento 2 facilitates the merchants to provide multiple things in invoice PDFs like order id, customer name, shipping address, product name, product quantity, product price, total amount, and so on.

However, depending on the business requirements, customization in invoice PDF can be done.

One such customization solution is offered in this post to create barcode and add it in Magento 2 invoice PDF.

Barcode in invoice PDF helps the customer to scan and get the order id using which it is easy to get order details.

Barcodes in invoices enhance the after-sales customer experience of the store. Barcodes are easy to use and decrease human errors.

Check the programmatic solution to add a barcode in invoice pdf in Magento 2 below:

Solution to Create Barcode and Add it in Magento 2 Invoice PDF

  1. Create di.xml file at Vendor\Extension\etc
  2. Create Invoice.php file in Vendor\Extension\Plugin\Invoice.php
    After doing this, the customers will start receiving invoice PDFs having a barcode. Stepwise Programmatic Solution to Generate Barcode in Invoice PDF in Magento 2

Done! That’s what you need to do.

If you have questions for this post, feel free to ask queries in the Comment section below.

I will try my level best to solve your queries.

Also, do consider sharing this post with Magento Community via social media. Your single share motivates me a lot.

Thank you.

Magento 2 Barcode Generator

Related Posts:

5
(based on 11 Reviews)
How to Create Barcode and Add it in Magento 2 Invoice PDF

Ronak Bhatti

Ronak is a Magento Developer at Meetanshi. He loves playing cricket. Apart from the work, he is an enthusiastic person who loves learning new skills.

8 Comments

  • monarc moso

    its shows error like Class ‘Zend\Barcode\Barcode’ not found shows on my version of code

    • Sanjay Jethva

      Hello Monarc,
      The mentioned issue is version specific issue as from Magento 2.3.6, it uses laminas instead of zend framework.
      You can use the below solution:
      Find the below line of code
      $barcodeResource = Barcode::factory($config)->draw();
      and replace it with
      $barcodeResource =\Zend_ Barcode::factory($config)->draw();

      Thank You

  • Saravanan

    Hi I am new to magento. I refer the internet and practicing. I searched for barcode to implement in invoice pdf. I choose your coding and implemented. I got the below error. Please help me to rectify.
    [InvalidArgumentException]
    Plugin class ColanDisributorsPluginInvoice doesn’t exist

  • smruti

    Hello,
    I have used this code in Magento 2.3.2 and 2.4.2 also but no barcode show at invoice .
    Please let us know the issue.
    Thanks.

    • Sanjay Jethva

      Hello Smruti,
      It’s working in Magento 2.3.2, please check the error log.
      And, it will not work in Magento 2.4.2 because it supports ‘laminas’ which you can use, instead of Zend classes.
      Thank You.

  • khushbu

    Hello,
    I have used Magento 2.3.5-p2 and add this code in module.
    But, its shows error like Class ‘Zend\Barcode\Barcode’ not found
    Please let us know the issue.
    Thanks.

Leave a Reply

Your email address will not be published. Required fields are marked *