title: Adding Order Comments to Magento Invoices
body: <p>I have been trying to get the customer comments, as well as gift message from orders to print on the invoices but no luck so far.</p>
  
  <p>I have tried some suggestions which I barely found but none are working.  There should be a simple way to do this but it baffles me that I dont seem to be able to find a solution</p>
  
  <p>I have also looked at many extensions but none seem to have this option</p>
  
  <p>I am using magento 1.7</p>
  
  <p>I would also want these to show in confirmation emails as well... any suggestions or ideas would be apprenticed </p>
  
  <p>Here is my invoice.php  (copied to local structure ) </p>
  
  <pre><code>class Mage_Sales_Model_Order_Pdf_Invoice extends 
  
  Mage_Sales_Model_Order_Pdf_Abstract
  {
  
      /***** Begin order comment modification *****/
  protected function _getCustomerOrderComments($invoice)
      {
          $order = $invoice-&gt;getOrder();
          if($orderComments = $order-&gt;getBiebersdorfCustomerordercomment()){
              return $orderComments;
          } else {
              return false;
          }
      }
   /***** End order comment modification *****/
  
  
      /**
       * Draw header for item table
       *
       * @param Zend_Pdf_Page $page
       * @return void
       */
      protected function _drawHeader(Zend_Pdf_Page $page)
      {
          /* Add table head */
          $this-&gt;_setFontRegular($page, 10);
          $page-&gt;setFillColor(new Zend_Pdf_Color_RGB(0.93, 0.92, 0.92));
          $page-&gt;setLineColor(new Zend_Pdf_Color_GrayScale(0.5));
          $page-&gt;setLineWidth(0.5);
          $page-&gt;drawRectangle(25, $this-&gt;y, 570, $this-&gt;y -15);
          $this-&gt;y -= 10;
          $page-&gt;setFillColor(new Zend_Pdf_Color_RGB(0, 0, 0));
  
          //columns headers
          $lines[0][] = array(
              'text' =&gt; Mage::helper('sales')-&gt;__('Products'),
              'feed' =&gt; 35
          );
  
          $lines[0][] = array(
              'text'  =&gt; Mage::helper('sales')-&gt;__('SKU'),
              'feed'  =&gt; 290,
              'align' =&gt; 'right'
          );
  
          $lines[0][] = array(
              'text'  =&gt; Mage::helper('sales')-&gt;__('Qty'),
              'feed'  =&gt; 435,
              'align' =&gt; 'right'
          );
  
          $lines[0][] = array(
              'text'  =&gt; Mage::helper('sales')-&gt;__('Price'),
              'feed'  =&gt; 360,
              'align' =&gt; 'right'
          );
  
          $lines[0][] = array(
              'text'  =&gt; Mage::helper('sales')-&gt;__('Tax'),
              'feed'  =&gt; 495,
              'align' =&gt; 'right'
          );
  
          $lines[0][] = array(
              'text'  =&gt; Mage::helper('sales')-&gt;__('Subtotal'),
              'feed'  =&gt; 565,
              'align' =&gt; 'right'
          );
  
          $lineBlock = array(
              'lines'  =&gt; $lines,
              'height' =&gt; 5
          );
  
          $this-&gt;drawLineBlocks($page, array($lineBlock), array('table_header' =&gt; true));
          $page-&gt;setFillColor(new Zend_Pdf_Color_GrayScale(0));
          $this-&gt;y -= 20;
      }
  
      /**
       * Return PDF document
       *
       * @param  array $invoices
       * @return Zend_Pdf
       */
      public function getPdf($invoices = array())
      {
          $this-&gt;_beforeGetPdf();
          $this-&gt;_initRenderer('invoice');
  
          $pdf = new Zend_Pdf();
          $this-&gt;_setPdf($pdf);
          $style = new Zend_Pdf_Style();
          $this-&gt;_setFontBold($style, 10);
  
          foreach ($invoices as $invoice) {
              if ($invoice-&gt;getStoreId()) {
                  Mage::app()-&gt;getLocale()-&gt;emulate($invoice-&gt;getStoreId());
                  Mage::app()-&gt;setCurrentStore($invoice-&gt;getStoreId());
              }
              $page  = $this-&gt;newPage();
              $order = $invoice-&gt;getOrder();
              /* Add image */
              $this-&gt;insertLogo($page, $invoice-&gt;getStore());
              /* Add address */
              $this-&gt;insertAddress($page, $invoice-&gt;getStore());
              /* Add head */
              $this-&gt;insertOrder(
                  $page,
                  $order,
                  Mage::getStoreConfigFlag(self::XML_PATH_SALES_PDF_INVOICE_PUT_ORDER_ID, $order-&gt;getStoreId())
              );
              /* Add document text and number */
              $this-&gt;insertDocumentNumber(
                  $page,
                  Mage::helper('sales')-&gt;__('Invoice # ') . $invoice-&gt;getIncrementId()
              );
              /* Add table */
              $this-&gt;_drawHeader($page);
              /* Add body */
              foreach ($invoice-&gt;getAllItems() as $item){
                  if ($item-&gt;getOrderItem()-&gt;getParentItem()) {
                      continue;
                  }
                  /* Draw item */
                  $this-&gt;_drawItem($item, $page, $order);
                  $page = end($pdf-&gt;pages);
              }
              /* Add totals */
              $this-&gt;insertTotals($page, $invoice);
              if ($invoice-&gt;getStoreId()) {
                  Mage::app()-&gt;getLocale()-&gt;revert();
              }
          }
  
  
          $message = Mage::getModel('giftmessage/message');
  
          $gift_message_id = $invoice-&gt;getOrder()-&gt;getGiftMessageId();
          if(!is_null($gift_message_id)) {
                $message-&gt;load((int)$gift_message_id);
                $gift_sender = $message-&gt;getData('sender');
                $gift_recipient = $message-&gt;getData('recipient');
                $gift_message = $message-&gt;getData('message');
                $page-&gt;drawText(Mage::helper('sales')-&gt;__('Message from:'), 35, $this-&gt;y, 'UTF-8');
               $page-&gt;drawText(Mage::helper('sales')-&gt;__($gift_sender), 120, $this-&gt;y, 'UTF-8');
                $this-&gt;y -=10;
                $page-&gt;drawText(Mage::helper('sales')-&gt;__('Message to:'), 35, $this-&gt;y, 'UTF-8');
                $page-&gt;drawText(Mage::helper('sales')-&gt;__($gift_recipient), 120, $this-&gt;y, 'UTF-8');
                $this-&gt;y -=20;
                $page-&gt;drawText(Mage::helper('sales')-&gt;__('Message:'), 35, $this-&gt;y, 'UTF-8');
                $page-&gt;drawText(Mage::helper('sales')-&gt;__($gift_message), 120, $this-&gt;y, 'UTF-8');
            }
  
         /***** Begin order comment modification *****/
          if($this-&gt;_getCustomerOrderComments($invoice)){
              $this-&gt;_setFontBold($page);
              $page-&gt;setFillColor(new Zend_Pdf_Color_RGB(0.93, 0.92, 0.92));
              $page-&gt;setLineColor(new Zend_Pdf_Color_GrayScale(0.5));
              $page-&gt;setLineWidth(0.5);
              $page-&gt;drawRectangle(25, $this-&gt;y, 570, $this-&gt;y-15);
              $this-&gt;y -=10;
              $page-&gt;setFillColor(new Zend_Pdf_Color_RGB(0.4, 0.4, 0.4));
              $page-&gt;drawText('Order comments:', 35, $this-&gt;y, 'UTF-8');
              $page-&gt;setFillColor(new Zend_Pdf_Color_GrayScale(0));
              $this-&gt;y -=20;
  
              $comments = $this-&gt;_getCustomerOrderComments($invoice)."\n";
  
              //wrap
              $comments = wordwrap($comments,118,"\n",false);
              $token = strtok($comments, "\n");
  
              while ($token != false) {
                  $page-&gt;drawText($token, 35, $this-&gt;y, 'UTF-8');
                  $this-&gt;y-=15;
                  $token = strtok("\n");
              }
  
              $this-&gt;y -=30;
              $this-&gt;_setFontRegular($page);
          }
          /***** end order comment modification *****/
  
  
          $this-&gt;_afterGetPdf();
          return $pdf;
      }
  
      /**
       * Create new page and assign to PDF object
       *
       * @param  array $settings
       * @return Zend_Pdf_Page
       */
      public function newPage(array $settings = array())
      {
          /* Add new table head */
          $page = $this-&gt;_getPdf()-&gt;newPage(Zend_Pdf_Page::SIZE_A4);
          $this-&gt;_getPdf()-&gt;pages[] = $page;
          $this-&gt;y = 800;
          if (!empty($settings['table_header'])) {
              $this-&gt;_drawHeader($page);
          }
          return $page;
      }
  }
  </code></pre>