Magento 2.1 Invoice PDF – How to Add Custom Text in Invoice PDF Header

magento-2.1

I need to add custom text below the Invoice No and before the Order No. I have tried with modifying insertDocumentNumber() method in vendor/magento/module-sales/Model/Order/Pdf/AbstractPdf.php. I have printed it but it is overlapping on the Invoice No label. Any help will be appreciated.

Best Answer

You need to edit just below three line in AbstractPdf.php

Replace line 391

$page->drawRectangle(25, $top, 570, $top - 70);

Instead of

$page->drawRectangle(25, $top, 570, $top - 55);

Replace line 397

$page->drawText(__('Order # ') . $order->getRealOrderId(), 35, $top -= 45, 'UTF-8');

instead of

$page->drawText(__('Order # ') . $order->getRealOrderId(), 35, $top -= 30, 'UTF-8');

Additional add after line no 621

$page->drawText('My Sample Text', 35, $docHeader[1] - 30, 'UTF-8');