Here I want to design and change the invoice PDF of a particular Invoice. I have added an observer to but it's creating a normal invoice. But I want to design and change the PDF of that particular invoice. I also have access to invoice's ID but I do not have any idea how to design the PDF and assign it to that particular invoice.

Here is my Observer

use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\Event\Observer;

class GenerateInvoice implements ObserverInterface

     * @inheritDoc
     * @var \Magento\Sales\Api\OrderRepositoryInterface
    protected $_orderRepository;

     * @var \Magento\Sales\Model\Service\InvoiceService
    protected $_invoiceService;

     * @var \Magento\Framework\DB\Transaction
    protected $_transaction;

    protected $invoiceSender;

    public function __construct(
        \Magento\Backend\Block\Template\Context $context,
        \Psr\Log\LoggerInterface $logger,
        \Magento\Framework\App\ResourceConnection $resource,
        \Magento\Sales\Api\OrderRepositoryInterface $orderRepository,
        \Magento\Sales\Model\Service\InvoiceService $invoiceService,
        \Magento\Framework\DB\Transaction $transaction,
        \Magento\Sales\Model\Order\Email\Sender\InvoiceSender $invoiceSender,      
        array $data = []

        $this->_orderRepository = $orderRepository;
        $this->_invoiceService = $invoiceService;
        $this->_transaction = $transaction;
        $this->_logger = $logger;
            $this->invoiceSender = $invoiceSender;

    public function execute(Observer $observer)

     $invoice = $observer->getEvent()->getInvoice();
    $order = $invoice->getOrder();
    $orderIncrementId = $order->getIncrementId();
    $date = date('d-M-Y');


        $order = $this->_orderRepository->get($entity_id);
        if($order->canInvoice()) {
            $invoice = $this->_invoiceService->prepareInvoice($order);
            $transactionSave = $this->_transaction->addObject(



        $this->_logger->info("Latest Invoice id ".$invoiceId);
        $this->_logger->info("Latest Invoice increment ".$incrementId);

                __('Notified customer Custom about invoice #%1.', $invoice->getId())




But its just generating Invoice I want this invoice's design to be done and changed.

How can I do this?

Small Help will be greatly appreciated.

Thanks in Advance :)

1 Answer 1


To modify Invoice PDF you must need to modify below files as per your requirement.


This File is used for all PDF generation so Make sure to modify as per compatibility with other PDF generation.


you can check and modify it as per your requirement.

Thank you

  • What if want to change in observer during the invoice generattion Apr 15, 2020 at 11:14
  • Observer is used to perform additional task or code to run for adding additional functionality. by using observer it will not forgot the default behaviour of it's own. so If you want to change the design of your invoice pdf you must need to override files as I mentioned in this solution. Apr 16, 2020 at 5:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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