1

I need to change name of the file generated from admin for PDF generated with ID of invoice.

2

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

| improve this answer | |

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.