Zend Framework PDF多线问题

Uff*_*ffo 9 php pdf zend-framework

我有一个问题,使用Zend_PDF多行,我的问题是我无法将整个文本写入我的pdf.My文本看起来像这样:http://pastebin.com/f6413f664

但是当我打开我的.pdf文件时,文本看起来像这样:http://screencast.com/t/1CBjvRodeZQd

这是我的代码:

    public function pdfAction()
{
    $this->_helper->layout->disableLayout();
    $this->_helper->viewRenderer->setNoRender();

    $theID = ($this->_getParam('id') !== NULL) ? (int)$this->_getParam('id') : false;

    ($theID === false) ? $this->_redirect('/home') : false;

    //Information
    $info = $this->artists->artistInfo($theID);

    // Create new PDF 
    $pdf = new Zend_Pdf(); 
    $pdf->properties['Title'] = "TITLE";
    $pdf->properties['Author'] = "AUTHOR";

    // Add new page to the document 
    $page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4); 
    $pdf->pages[] = $page; 

    // Set font 
    $page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 8); 

    // Draw text
     foreach (explode("</p>", $info[0]['biography']) as $i => $line) {
       $page->drawText($line, 0, 820 - $i * 10, 'UTF-8');
     }

    $this->getResponse()->setHeader('Content-type', 'application/x-pdf', true);
    $this->getResponse()->setHeader('Content-disposition', 'attachment; filename=my-file.pdf', true);
    $this->getResponse()->setBody($pdf->render());
}
Run Code Online (Sandbox Code Playgroud)

我想做的是,每个<p>人都休息一下(<br />\n)并显示整个文本.

有什么解决方案吗

And*_*ann 18

而不是这个:

 // Draw text
 foreach (explode("</p>", $info[0]['biography']) as $i => $line) {
   $page->drawText($line, 0, 820 - $i * 10, 'UTF-8');
 }
Run Code Online (Sandbox Code Playgroud)

尝试一下(没试过):

// Draw text    
$charsPerLine = 50;
$heightPerLine = 10;

$text = str_replace('<p>','',$info[0]['biography']);
$lines = array();

foreach (explode("</p>", $text) as $line) {
    $lines = array_merge(
                    $lines, 
                    explode(
                            "\n",
                            wordwrap($line, $charsPerLine, "\n")
                    )
    );
}

foreach ( $lines as $i=>$line ) {
    $page->drawText($line, 0, 820 - $i * $heightPerLine, 'UTF-8');
}
Run Code Online (Sandbox Code Playgroud)

您显然需要使用这两个"常量"来获得最佳效果.

希望能帮助到你.