Search code examples
phpmagentozend-frameworknewlinemagento-1.9

How to write new line with drawText() in magento?


I am trying to put a new line with the Magento function drawText(); I was trying the code below but it showing all statement like Line 1! \n Line 1!

Can anyone tell me how I can print multiple new lines using the following code.

 $page->drawText(Mage::helper('sales')->__('Line 1! \n Line 1!'), 35, $this->y, 'UTF-8');

Solution

  • Do a separate call to $page->drawText for each line, as per this - PHP + PDF Line Break

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