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

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:

Get Weekly Updates

Never miss Magento tips, tricks, tutorials, and news.

Thank you for subscribing.

Something went wrong.

5
(based on 11 Reviews)

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.

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

  • 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

    • Hello,
      Please check if the path given at the plugin in di.xml has the Invoice.php file or not. Also, check if the namespace is correct in the Invoice.php file.
      Thanks.

  • 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.

    • 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.

  • 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.