Categories: How To

How to Add Signature Image in Magento Invoice PDF

With the wider expansion of Internet use, large and even small organizations have been accelerating the use of E-Invoicing. The drive to save environment and stop using papers has led to incorporate e-billing and e-statements in invoicing. Being a popular platform, Magento store owners have started implementing the same in their order invoices.

Digitally signed invoices provide immediate benefits in terms of time saving, cost and most importantly, environment saving. Making them digitally signed makes them legal and provides authenticity and trust. Recently working with a client, he asked us to add digital signature image in his Magento order invoice which drove us to implement a custom code to fulfill the needs.

Here, I’m sharing custom code to add signature image in Magento invoice PDF

Go to App >> Code >> Core >> Mage >> Sales >> Model >> Order >> Pdf >> Invoice.php and put
$this->insertSignature($page, $invoice->getStore()); at line number 153.

Note: Rather than changing in core file, we recommend you to overwrite.

Now add below function in the same file:

protected function insertSignature(&$page, $store = null)
    {
  $this->y = $this->y ? $this->y : 815;
        $image = 'Add Image Path';
            if (is_file($image)) {
                $image       = Zend_Pdf_Image::imageWithPath($image);
                $top         =  $this->y - 50; 
                $widthLimit  = 100; 
                $heightLimit = 100; 
                $width       = $image->getPixelWidth();
                $height      = $image->getPixelHeight();

                //preserving aspect ratio (proportions)
                $ratio = $width / $height;
                if ($ratio > 1 && $width > $widthLimit) {
                    $width  = $widthLimit;
                    $height = $width / $ratio;
                } elseif ($ratio < 1 && $height > $heightLimit) {
                    $height = $heightLimit;
                    $width  = $height * $ratio;
                } elseif ($ratio == 1 && $height > $heightLimit) {
                    $height = $heightLimit;
                    $width  = $widthLimit;
                }

                $y1 = $top - $height;
                $y2 = $top;
                $x1 = 450;
                $x2 = $x1 + $width;
                
    $imgY = $this->y - $height - 60 ; 
    
    $page->drawImage($image, $x1, $y1, $x2, $y2);
    $page->drawText(Mage::helper('sales')->__('Authorized Signatory') ,$x1, $imgY ,'UTF-8');
    $page->drawText(Mage::helper('sales')->__('MageComp') ,$x1, ($top + 3) ,'UTF-8');

                $this->y = $y1 - 10;
        }
    }

Implementing the above code will successfully add signature image in Magento invoice. Let me know if you want more help or send me feedback through commenting.

Happy Coding

 

Click to rate this post!
[Total: 7 Average: 4.6]
Dhiren Vasoya

Dhiren Vasoya is a Director and Co-founder at MageComp, Passionate ?️ Certified Magento Developer?‍?. He has more than 9 years of experience in Magento Development and completed 850+ projects to solve the most important E-commerce challenges. He is fond❤️ of coding and if he is not busy developing then you can find him at the cricket ground, hitting boundaries.?

Recent Posts

How to Add Tooltip in Checkout Shipping Field in Magento 2?

Hello Magento Friends, In today’s blog, I will explain How to Add Tooltip in Checkout…

9 hours ago

How to Integrate and Use MongoDB with Laravel?

MongoDB is a popular NoSQL database that offers flexibility and scalability when handling modern web…

2 days ago

NodeJS | Callback Function

In NodeJS, callbacks empower developers to execute asynchronous operations like reading files, handling requests, and…

2 days ago

How to Show SKU in Order Summary in Magento 2?

Hello Magento Friends, In today’s blog, we will learn How to Show SKU in Order…

4 days ago

Best Colors to Use for CTA Buttons

The "Buy Now" and "Add to Cart" buttons serve as the primary call-to-action (CTA) elements…

6 days ago

Magento 2: How to Save Custom Field Value to quote_address for Multi-Shipping Orders

Hello Magento Friends, In Magento 2, the checkout process allows customers to choose multiple shipping…

1 week ago