I have added extra data to be display before subtotal in INvoice PDF but not display properly
Following is my code I added
foreach ($invoice->getAllItems() as $item) {
if ($item->getOrderItem()->getParentItem()) {
continue;
}
/* Draw item */
$this->_drawItem($item, $page, $order);
$page->setLineColor(new \Zend_Pdf_Color_GrayScale(0.5));
$page->setLineWidth(0.5);
$page->drawLine(25, $this->y+12.5, 570, $this->y+12.5);
$page = end($pdf->pages);
}
$this->insertText($page,$order->getGiftMessageId());
/* Add totals */
$this->insertTotals($page, $invoice);
if ($invoice->getStoreId()) {
$this->_localeResolver->revert();
}
Where $this->insertText($page,$order->getGiftMessageId()); is my custom function
Also, following is the data for this function
public function insertText($page,$giftid)
{
$page->drawLine(25, $this->y, 570, $this->y);
$this->y -= 25;
$lines = [];
$_giftMessage = $helper = \Magento\Framework\App\ObjectManager::getInstance()->get('Magento\GiftMessage\Helper\Message')->getGiftMessage($giftid);
if (!empty($_giftMessage->getSender())) {
$page->drawText('Gift Message for this Order 2', 35, $this->y, 'UTF-8');
$page->drawText('From:', 35, $this->y-26, 'UTF-8');
$page->drawText($_giftMessage->getSender(), 65, $this->y-40, 'UTF-8');
$page->drawText('To:', 35, $this->y-50, 'UTF-8');
$page->drawText($_giftMessage->getRecipient(), 65, $this->y-60, 'UTF-8');
$page->drawText('Message:', 35, $this->y-75, 'UTF-8');
$page->drawText($_giftMessage->getMessage(), 65, $this->y-90, 'UTF-8');
}
}
}
The custom data gets hidden