I want to change the filenames of the PDF files in Magento 2.
The default names are not clear and I want invoices to be searchable when saved to a location on my pc.
Is it possible to change the filenames of the PDF-files in Magento 2 to a format like “invoice_1000000123.pdf”?
3
Answers
Yes it is possible to change invoice pdf filename.
Please go to following path:
You can change filename from above file.
You should never edit core files. Seriously, don’t.
Since
/vendor/magento/module-sales/Controller/Adminhtml/Invoice/AbstractInvoice/PrintAction.php
is an abstract class you have to use a plugin or preference in your module in order to override it.What you need to achieve that:
The usual minimum files:
/Vendor/Module/composer.json
,/Vendor/Module/registration.php
,/Vendor/Module/etc/module.xml
In
/Vendor/Module/etc/module.xml
you should sequence Magento_SalesThen you can either use a plugin or a preference in
/Vendor/Module/etc/di.xml
Plugin would look something like this:
Now add a
PrintAction.php
to the path specified in your preference / plugin (Example for preference)You need override the invoice admin controller.
In your custom module admin controller, You need to change the name of Pdf file.
Reference Link