0

I am working on Magento 2.3. I need to change the name of PDF file which is attached in invoice email.

In invoice we have send email button. When we click customer will get invoice email with invoice pdf attachment. I want to change that PDF name. Anyone know from where I can find that name and change ?

2
0

Reference Link

In this case, I think we need override the invoice admin controller by using preference.

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="\Magento\Sales\Controller\Adminhtml\Order\Invoice" 
      type="Vendor\Module\Controller\Adminhtml\Order\Invoice" />
</config>

In the custom admin controller, we need to change the name of Pdf file.

public function execute() 
{
  $invoiceId = $this->getRequest()->getParam('invoice_id');
  ......
  return $this->_fileFactory->create(
                    'invoice_00000' . $invoiceId . '.pdf', //<== Change the name here.
                    $pdf->render(),
                    DirectoryList::VAR_DIR,
                    'application/pdf'
                );
  ...... 
}

Should read more about create method in vendor/magento/framework/App/Response/Http/FileFactory.php

2
  • I want to chaneg the name in email attachment file. This will change the name there ? – David Coder Jun 4 at 11:20
  • I tried this but not working on email. – David Coder Jun 4 at 11:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.