1

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

enter image description here

4
  • are you sure the code was run? you can create a node checkpoint then debugging Commented Jul 1, 2020 at 8:03
  • and, we should not use ObjectManager::getInstance(). Instead, let's use Dependency Injection. Commented Jul 1, 2020 at 8:06
  • yes the code ran perfectly. you can see 'Gift Message for this Order 2' in PDF but the data after that where not printed on next page.
    – Arjun
    Commented Jul 1, 2020 at 8:11
  • The content in 'Gift Message for this Order 2' should be auto set after product details
    – Arjun
    Commented Jul 1, 2020 at 8:11

0

Your Answer

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

Browse other questions tagged or ask your own question.