Magento by default do not display comments in pdf. So I wrote this code.

$commentsCollection = $source->getCommentsCollection(true);
        $internalcomments = "";
            $internalcomments = "NOTES:";
        if ($this->y <= 20) {
                $page = $this->newPage();
                $this->y = 800;
        $page->setFont(\Zend_Pdf_Font::fontWithName(\Zend_Pdf_Font::FONT_HELVETICA), 7);
        $this->_setFontBold($page, 10);
        $this->y -=10;
        $page->drawText($internalcomments, 30, $this->y, 'UTF-8');
        $this->_setFontRegular($page, 10);
        $this->y -= 15;

        foreach($commentsCollection as $comm)
                $textChunk = wordwrap($comm->getData('comment'), 120, "\n");
                foreach(explode("\n", $textChunk) as $textLine){
                        if ($textLine!=='') {
                                $page->drawText(strip_tags(ltrim($textLine)), 30, $this->y, 'UTF-8');
                                $this->y -= 15;


I am facing a weird issue where invoice pdf contains character like empty box or empty box with cross in it only when you add comments in multiple lines (press enter) while generating invoice. If you add comments in multiple lines later on (when invoice is already generated) this issue does not occur.

enter image description here

I assumed the font might be the issue. So I changed the font to DejaVuSans. However it did not solve my problem.

Any help would be appreciated.

  • using UTF-8 in your meta tag. it may solve this issue Jun 20, 2017 at 11:37
  • @Sejal Shah I'm trying to add comments to a pdf. What file did you add this code to? Jan 14, 2019 at 12:14
  • You need to override vendor/magento/module-sales/Model/Order/Pdf/Invoice.php
    – Sejal Shah
    Jan 14, 2019 at 12:41

1 Answer 1


Resolved the issue by changing a piece of code

foreach($commentsCollection as $comm)
                $value = preg_replace('/<br[^>]*>/i', "\n", $comm->getData('comment'));
                foreach(explode("\n", $value) as $textLine){
                        $this->y -= 10;


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.