title: Magento PDF Invoice Content Layout Issues
body: <p>I am not good with PDF's at all. I have added two secions below that are commented called "Invoice Comments and Order Comments". The trouble I am having is that I cannot put these two sections in a nice cell. When I try things like <code>$pdf-&gt;Cell</code> and etc. I just get the dreaded white screen. For some reason it seems that only <code>drawText</code> works with rendering the text. Also, the comments are extending off of the PDF page. I have tried to enter line breaks with no success. I guess its b/c the comments are Arrays. Any help would be great.</p>
  
  <pre><code>class Inchoo_Invoice_Model_Order_Pdf_Invoice extends Mage_Sales_Model_Order_Pdf_Invoice
  {
      protected function insertImage($image, $x1, $y1, $x2, $y2, $width, $height, &amp;$page)
      {
          if (!is_null($image)) {
              try{
                  $width = (int) $width;
                  $height = (int) $height;
  
                  //Get product image and resize it
                  $imagePath = Mage::helper('catalog/image')-&gt;init($image, 'image')
                      -&gt;keepAspectRatio(true)
                      -&gt;keepFrame(false)
                      -&gt;resize($width, $height)
                      -&gt;__toString();
  
                  $imageLocation = substr($imagePath,strlen(Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB)));
                  $image = Zend_Pdf_Image::imageWithPath($imageLocation);
                  //Draw image to PDF
                  $page-&gt;drawImage($image, $x1, $y1, $x2, $y2);
              }
              catch (Exception $e) {
                  return false;
              }
          }
      }
  
  
  
      public function getPdf($invoices = array())
      {
          $width = 1000;
          $height = 1000;
          $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());
              }
              $page = $pdf-&gt;newPage(Zend_Pdf_Page::SIZE_A4);
              $pdf-&gt;pages[] = $page;
  
              $order = $invoice-&gt;getOrder();
  
              /* Add image */
              $this-&gt;insertLogo($page, $invoice-&gt;getStore());
  
  
              /* Add address */
              $this-&gt;insertAddress($page, $invoice-&gt;getStore());
  
              /* Add head */
                          $page-&gt;drawText(Mage::helper('sales')-&gt;__('Invoice # ') . $invoice-&gt;getIncrementId(), 487, 780, 'UTF-8');
              $this-&gt;insertOrder($page, $order, Mage::getStoreConfigFlag(self::XML_PATH_SALES_PDF_INVOICE_PUT_ORDER_ID, $order-&gt;getStoreId()));
  
              $page-&gt;setFillColor(new Zend_Pdf_Color_GrayScale(1));
              $this-&gt;_setFontRegular($page);
  
  
              /* Add table */
              $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;
  
              /* Add table head */
              $page-&gt;setFillColor(new Zend_Pdf_Color_RGB(0.4, 0.4, 0.4));
              $page-&gt;drawText(Mage::helper('sales')-&gt;__('Products'), 35, $this-&gt;y, 'UTF-8');
              //Added for product image
              $page-&gt;drawText(Mage::helper('sales')-&gt;__('Product Image'), 279, $this-&gt;y, 'UTF-8');
              $page-&gt;drawText(Mage::helper('sales')-&gt;__('SKU'), 125, $this-&gt;y, 'UTF-8');
              $page-&gt;drawText(Mage::helper('sales')-&gt;__('Price'), 380, $this-&gt;y, 'UTF-8');
              $page-&gt;drawText(Mage::helper('sales')-&gt;__('Qty'), 430, $this-&gt;y, 'UTF-8');
              $page-&gt;drawText(Mage::helper('sales')-&gt;__('Tax'), 480, $this-&gt;y, 'UTF-8');
              $page-&gt;drawText(Mage::helper('sales')-&gt;__('Subtotal'), 535, $this-&gt;y, 'UTF-8');
  
              $this-&gt;y -=15;
  
              $page-&gt;setFillColor(new Zend_Pdf_Color_GrayScale(0));
  
              /* Add body */
              foreach ($invoice-&gt;getAllItems() as $item){
                  if ($item-&gt;getOrderItem()-&gt;getParentItem()) {
                      continue;
                  }
  
                  if ($this-&gt;y &lt; 15) {
                      $page = $this-&gt;newPage(array('table_header' =&gt; true));
                  }
  
                  /* Draw item */
                  $page = $this-&gt;_drawItem($item, $page, $order);
  
                  /* Draw product image */
                  $productId = $item-&gt;getOrderItem()-&gt;getProductId();
                  $image = Mage::getModel('catalog/product')-&gt;load($productId);
                  $this-&gt;insertImage($image, 345, (int)($this-&gt;y + 0), 275, (int)($this-&gt;y+65), $width, $height, $page);
              }
  
              /* Add totals */
              $page = $this-&gt;insertTotals($page, $invoice);
  
  
  
  
  
  
  
  
  /*************************** This Is The Invoice Comments ***********************************/
  $_tempY = $this-&gt;y;
  $this-&gt;y += 10;
  
  $commentsCollection = $invoice-&gt;getCommentsCollection(true);
  
  $internalcomments = "Internal Invoice Comments";    
  $page-&gt;drawText($internalcomments, 35, $this-&gt;y, 'UTF-8'); 
  
              foreach($commentsCollection as $comm)
              {
                  $page-&gt;drawText($comm-&gt;getData('comment'), 235, $this-&gt;y, 'UTF-8');
                  $this-&gt;y -= 10;
  
              } 
  
  /*************************** End Invoice Comments ***********************************/
  
  
  
  
  
  
  
              if ($invoice-&gt;getStoreId()) {
                  Mage::app()-&gt;getLocale()-&gt;revert();
              }
          }
  
  
  
  
  
  /************************* This Is The Order Comments *******************************/
  
  $_tempY = $this-&gt;y;
  $this-&gt;y -= 80;
  
  $statusHistoryCollection = $order-&gt;getStatusHistoryCollection();
  $customersection = "Order Customer Comments";
     $page-&gt;drawText($customersection, 35, $this-&gt;y, 'UTF-8'); 
  foreach ($statusHistoryCollection as $statushistory) {  
     $page-&gt;drawText($statushistory-&gt;getComment(), 35, $this-&gt;y, 'UTF-8');
     $this-&gt;y -= 10;
  }
  
  $this-&gt;y = $_tempY;
  
  /************************* End Order Comments *******************************/
  
  
  
          $this-&gt;_afterGetPdf();
  
          return $pdf;
      }
  
  
  
  }
  </code></pre>