Generate an Auto Invoice Programmatically from Magento 2 required an order id. Based on the Order Id, You can fetch Order Object.
Given code, a snippet is used to generate an Invoice in Magento, After generating an invoice automatically sends the invoice mail to a customer who has placed the order.
I have just given a demo to create an invoice with the specified order id,

Hi Rakesh,
Thank you for sharing such a knowledgeable blog and programme code.
Thank you
Hi Rakesh,
Thank you for sharing such a knowledgeable blog and programme code.
Thank you
This extension generates the invoice automatically on order creation
https://webpanda-solutions.com/auto-invoice-shipment.html