2

I have success to test my code with function Zend_Pdf() for easy to understand, this is my code :

    $pdf = new Zend_Pdf();
    $page = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_A4);
    $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA);
    // set font for page
    // write text to page
        $test = "This is reporting for <br /> hello world: LALALA......";
    $page->setFont($font, 15)
        ->drawText('That which we call a rose,', 72,720)
        ->drawText("$test", 72, 620);
    // add page to document
    $pdf->pages[] = $page;
    $pdf->save("data/reports/" . $_SESSION['User_fonction'] ."-report.pdf");

My cods will show in pdf file

That which we call a rose

and This is reporting for <br /> hello world: LALALA......

My question

how i can resolve this problem by i can write tag html in it by well like tag <br /> is should know ? any one used to understand on it please. Any help ...

I am looking forword to see your reply soon. thanks .

koe
  • 736
  • 1
  • 12
  • 33

2 Answers2

2

What you want to achieve is you have html (so text with markup) and that must be converted into a PDF file. This is unfortunately not the goal of Zend_Pdf. The pdf component allows only to set plain text and not any markup attached.

You can use a Zend Framework 2 module (you tagged your question with zend-framework-2, I assume you use it then) called DomPdfModule. You use Zend Framework 2 view scripts to render the result and use above module to convert it into a PDF file.

Jurian Sluiman
  • 13,498
  • 3
  • 67
  • 99
  • 1
    thanks for this info, it's a good solution but i can't up-grand full of my project by this point. but any way i will chose it for my second project – koe Jul 17 '13 at 10:05
1

Zend_PDF won't handle HTML, you should try something such as:

http://www.tcpdf.org/

http://code.google.com/p/wkhtmltopdf/
Andrew
  • 12,617
  • 1
  • 34
  • 48
  • my point as pointed out above is that Zend_PDF won't handle writing of HTML inside PDF documents, it's not meant for that kind of usage. You should try a library made specifically for that reason, such as the ones pointed out – Andrew Jul 17 '13 at 09:13