PDF Generation with Symfony2 – Part II: Zend Option

To start this post we must acknowledge the existence of a Zend library to fill in pdfs here and also the fact that there were some people who had used it before even if it was as far as I know only in the 1.x version like here.

The integration between Symfony2 and Zend2 is rather simple since both support namespaces the only thing left is (adapted from here):

git submodule add git://github.com/zendframework/zf2.git vendor/Zend

And register the namespace:

 'Zend'                => __DIR__.'/../vendor/Zend/library',

And the demo code:

$zf2pdf = new \Zend\Pdf\PdfDocument(__DIR__.'/../pathtoyourfile/test.pdf', null, true);
$page = $zf2pdf->pages[0];
$style = new \Zend\Pdf\Style();
$style->setFont(\Zend\Pdf\Font::fontWithName(\Zend\Pdf\Font::FONT_HELVETICA),12);
$style->setFontSize(12);
$page->setFont($style->getFont(), $style->getFontSize());
$page->drawText('Hello world!', 72, 720);
$zf2pdf->save(__DIR__.'/../pathtoyourfile/testout.pdf');

Here we just used the Zend framework classes to work it out without documentation like it used to be in Symfony2. Please help us help you and write more blogs like this by donating on the top right corner of the site.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>