在两行文字zend pdf中包含换行符

时间:2016-01-05 09:53:52

标签: php magento pdf zend-framework

我有两行来自Magento静态块的文本,我需要将其包含在pdf中。我使用zend php pdf函数。

任何人都可以告诉我如何通过两行来实现换行。

 protected function financeAdvert($page){
            $finance_advert = Mage::app()->getLayout()->createBlock('cms/block')->setBlockId('pdf_advert')->toHtml(); 
            $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA);
            $page->setFont($font, 8);
            $fin_ad[]= wordwrap($finance_advert,50,'<br>',true);
            $page->setFillColor(new Zend_Pdf_Color_Html('#000000'))->drawText(strip_tags($fin_ad), 70, 245, 'UTF-8');
}

1 个答案:

答案 0 :(得分:1)

答案是

 protected function financeAdvert($page){

            $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA);
            $page->setFont($font, 8);
            $finance_advert = Mage::app()->getLayout()->createBlock('cms/block')->setBlockId('pdf_advert')->toHtml(); 
            $yPos = 245;
            foreach (explode('|', $finance_advert) as $str) {
                foreach (Mage::helper('core/string')->str_split($str, 100, true, true) as $part) {
                    $fin_advert[] = $page->setFillColor(new Zend_Pdf_Color_Html('#000000'))->drawText(strip_tags($part), 50, $yPos, 'UTF-8');
                     foreach ($fin_advert as $yPosition){
                        $yPos-=10;
                    }
                }
            }
    }

当每100个字符出现&#34; |&#34;符号