Question

How to display "hello world" on multiple pages in a single PDF document using Zend_Pdf?

 $pdf = new Zend_Pdf(); 
 $page = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_A4);
$font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA);
$page->setFont($font, 24) ->drawText('Hello World,', 72, 720);
 $pdf->pages[] = $page;
 $pdf->save('new.pdf');

I have tried the above code but is not able write chunk of code for iterating multiple pages

Was it helpful?

Solution

Following the comment I just made, I am posting as an answer because code doesn't render well in comments. If you want multiple pages with the same text, I guess you could simply do a loop:

<?php
    $pdf = new Zend_Pdf(); 
    $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA);

    for($i=0; $i<5; $i++) {
        $page = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_A4);
        $page->setFont($font, 24) ->drawText('Hello World page '.$i, 72, 720);
        $pdf->pages[] = $page;
    }

    $pdf->save('new.pdf');
?>

I haven't tested the code because, like h2ooooooo, I don't really use Zend_Pdf.

OTHER TIPS

I'll be honest and say that I have no idea how Zend_Pdf works, but I can imagine something like this would work:

<?php
    $pdf = new Zend_Pdf(); 
    $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA);

    $page = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_A4);
    $page->setFont($font, 24) ->drawText('Hello World page one,', 72, 720);
    $pdf->pages[] = $page;

    $page = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_A4);
    $page->setFont($font, 24) ->drawText('Hello World page two,', 72, 720);
    $pdf->pages[] = $page;

    $pdf->save('new.pdf');
?>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top