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

1 Answer 1


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" />

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.

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

  • How to change attached file name on Invoice email ? Jun 4, 2021 at 11:28

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.