How to Add Signature Image in Magento Invoice PDF

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

 

Previous Article

How to Install Magento SUPEE 10266 With or Without SSH

Next Article

How to Send Order Confirmation Email After Successful Payment in Magento 2

Write a Comment

Leave a Comment

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

Get Connect With Us

Subscribe to our email newsletter to get the latest posts delivered right to your email.
Pure inspiration, zero spam ✨