I have been able to insert new lines on my pdf invoice. It is working perfectly with positioning in right place.

However, when invoice content gets bigger but only total part goes to second page, my inserted new lines don't go to second page.

If products are moving to second page then only those new lines moves to second page after total.

I have tried with setting $this->y -=10 (any number), but it keeps moving in first page.

How do I force them to be below the total all the time? Any idea on this?


Screenshots: enter image description here

  • How are you making new lines now? \r\n? Commented Jun 2, 2015 at 0:28
  • $page->drawLine(20, $this->y -=10, 570, $this->y, Zend_Pdf_page::SHAPE_DRAW_STROKE); and $page->drawText("Bank Detail: ", 30, $this->y -=20, 'UTF-8');. These lines suppose to be under the Total all the time. Commented Jun 2, 2015 at 0:36
  • @AdarshKhatri, Hello I am facing same problem, please comment if you found any solution. Commented Dec 2, 2015 at 5:54
  • No, I haven't yet. Please add here if you find any. Commented Dec 16, 2015 at 5:04
  • @VinayaMaheshwari, please check magento.stackexchange.com/questions/69715/… It worked for me. Commented Feb 8, 2016 at 0:33

2 Answers 2


So, I believe you are looking for something like this (because you need line breaks - notice \n):

$textChunk = wordwrap($value, 20, "\n");
foreach(explode("\n", $textChunk) as $textLine){
  if ($textLine!=='') {
    $page->drawText(strip_tags(ltrim($textLine)), 75, $line, 'UTF-8');
    $line -=14;

I grabbed this code from Stackoverflow

  • Thanks, it's not about inserting new line. My new lines are not sticking with total block. I have added screenshot, please see update. Commented Jun 2, 2015 at 0:59
  • Look at the $line -=14; value. You need to increment this each time to "move down the page" Commented Jun 2, 2015 at 1:00

Alright, after digging into magento core functions, here is how I have achieved this:

My Namespace_ModuleName_Model_Sales_Order_Pdf_Invoice extends Mage_Sales_Model_Order_Pdf_Invoice class

public function getPdf($invoices = array())
  //other stuff

 foreach ($invoices as $invoice) {
  //other stuff

      /* Add totals */
        $this->insertTotals($page, $invoice);
        if ($invoice->getStoreId()) {

     /* my new content
      * insert few lines, admin user etc
      $page = end($pdf->pages); ///this is very important to force it go after total block ////
      $this->_insertPaidHistory($page, $invoice); //have separate custom function
    return $pdf;


Did you notice $page = end($pdf->pages); right before my new content! That's responsible to force my contenct always go after total block.

Hope this will help someone.

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.