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
Hello Magento Friends, In today’s blog, I will explain How to Add Tooltip in Checkout…
MongoDB is a popular NoSQL database that offers flexibility and scalability when handling modern web…
In NodeJS, callbacks empower developers to execute asynchronous operations like reading files, handling requests, and…
Hello Magento Friends, In today’s blog, we will learn How to Show SKU in Order…
The "Buy Now" and "Add to Cart" buttons serve as the primary call-to-action (CTA) elements…
Hello Magento Friends, In Magento 2, the checkout process allows customers to choose multiple shipping…