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();
$page->setFont($style->getFont(), $style->getFontSize());
$page->drawText('Hello world!', 72, 720);

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.