2009-08-25 31 views
9

ben şöyle bir sorun, Zend_Pdf satırlı ile, benim sorunum ben benim pdf.My metne tüm metnini yazamazsınız olmasıdır vardır: http://pastebin.com/f6413f664Zend Framework PDF satırlı sorunları

Ama açtığınızda benim .pdf dosyası, metin şuna benzer: http://screencast.com/t/1CBjvRodeZQd

ve işte benim kodudur: her <p> bir mola (n \ <br />) ve gerektirecek bir neden de yapmak istediğim ne

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()); 
} 

olduğu tüm metni görüntüle.

Çözüm herhangi bir adam? Bunun yerine

cevap

17

:

// 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'); 
} 

Açıkçası iyi sonuçları almak için bu 2 "sabitler" ile oynamak gerekir:

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

bu bir deneyin (bunu deneyin vermedi) ver .

Yardım edin.

+0

Evet, işe yarıyor! Ama bir sorum daha var, nasıl bir başlığa metnin üstünü koyabilirim? – Uffo

+0

koddaki 820'yi ~ 800 olarak değiştirin ve başlığınızı yazdırmak için başka bir drawText çağrısı ekleyin –

+0

Thx a lot man !! – Uffo