AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
Magento invoice template pdf8/23/2023 ![]() ![]() How to change PDF Invoice Logo, Shippment logo in Magento 2įollow the simple way to do this: 3 Steps to setup invoices and packing slips $this->message->createAttachment($pdfString,'application/pdf',\Zend_Mime::DISPOSITION_ATTACHMENT,\Zend_Mime::ENCODING_BASE64,'attachment.Impress your customers with professional PDF invoices that match your store's branding Public function addAttachment($pdfString) namespace CompanyName\ModuleName\Model\Mail Ĭlass TransportBuilder extends \Magento\Framework\Mail\Template\TransportBuilder Then, You need to create another file at app/code/CompanyName/ModuleName/Model/Mail and add below code inside the file. Header("Content-type: application/x-pdf") Header("Content-Disposition: inline filename=pdfresult.pdf") $pdfData = $pdf->render() // Get PDF document as a string $page->drawText("Company Name", 70, $footer, 'UTF-8') $page->setFont(\Zend_Pdf_Font::fontWithName(\Zend_Pdf_Font::FONT_HELVETICA), 9) $page->drawText("Customer Email : ".$customeremail, $left, $top-165,'UTF-8') $page->drawText("Customer Name : ".$customername, $left, $top-140,'UTF-8') $page->setFont(\Zend_Pdf_Font::fontWithName(\Zend_Pdf_Font::FONT_HELVETICA), 14) //Set Font $page->setFont(\Zend_Pdf_Font::fontWithName(\Zend_Pdf_Font::FONT_HELVETICA), 20) //Set Font $page = $pdf->newPage(\Zend_Pdf_Page::SIZE_A4) $pdf = new \Zend_Pdf() //Create new PDF file Public function createPdf( $customername,$customeremail) $image = \Zend_Pdf_Image::imageWithPath($this->_mediaDirectory->getAbsolutePath($imagePath)) If($this->_mediaDirectory->isFile($imagePath)) $image = $this->scopeConfig->getValue('sales/identity/logo',\Magento\Store\Model\ScopeInterface::SCOPE_STORE,$this->_modelStoreManagerInterface->getStore()->getId()) $this->_logLoggerInterface->debug($e->getMessage()) $resultJson = $this->resultFactory->create(ResultFactory::TYPE_JSON) >addTo($this->scopeConfig->getValue(self::XML_PATH_EMAIL_ADMIN_EMAIL, $storeScope)) >setFrom($this->scopeConfig->getValue(self::XML_PATH_EMAIL_ADMIN_QUOTE_SENDER, $storeScope)) >setTemplateIdentifier($this->scopeConfig->getValue(self::XML_PATH_EMAIL_ADMIN_QUOTE_NOTIFICATION, $storeScope)) $storeScope = ScopeInterface::SCOPE_STORE $pdfContent = $this->createPdf($customerName,$email) $this->_mediaDirectory = $filesystem->getDirectoryWrite(DirectoryList::MEDIA) $this->_transportBuilder = $quoteTransportBuilder $this->_logLoggerInterface = $logLoggerInterface $this->inlineTranslation = $inlineTranslation $this->_modelStoreManagerInterface = $modelStoreManagerInterface $this->scopeConfig = $configScopeConfigInterface \Magento\Framework\Filesystem $filesystem \Magento\Framework\Mail\Template\TransportBuilder $quoteTransportBuilder, ScopeConfigInterface $configScopeConfigInterface, StoreManagerInterface $modelStoreManagerInterface, ![]() Use Magento\Framework\App\Filesystem\DirectoryList Ĭonst XML_PATH_EMAIL_ADMIN_QUOTE_SENDER = 'emailcustom/general/sender' Ĭonst XML_PATH_EMAIL_ADMIN_QUOTE_NOTIFICATION = 'emailcustom/general/template' Ĭonst XML_PATH_EMAIL_ADMIN_EMAIL = 'emailcustom/general/reciver' Use Magento\Framework\Controller\ResultFactory Use Magento\Framework\Translate\Inline\StateInterface Use Magento\Store\Model\StoreManagerInterface Use Magento\Framework\App\Config\ScopeConfigInterface Use Magento\Framework\App\Action\Context namespace CompanyName\ModuleName\Controller\Index ![]() Create Sendmail.php file at app/code/CompanyName/ModuleName/Controller/Index and write the following code in it.
0 Comments
Read More
Leave a Reply. |