Symfony2 - PdfBundle not working

Posted by ElPiter on Stack Overflow See other posts from Stack Overflow or by ElPiter
Published on 2012-12-01T01:03:40Z Indexed on 2012/12/01 11:05 UTC
Read the original article Hit count: 351

Filed under:
|
|
|

Using Symfony2 and PdfBundle to generate dynamically PDF files, I don't get to generate the files indeed.

Following documentation instructions, I have set up all the bundle thing:

autoload.php:

'Ps' => __DIR__.'/../vendor/bundles',
'PHPPdf' => __DIR__.'/../vendor/PHPPdf/lib',
'Imagine' => array(__DIR__.'/../vendor/PHPPdf/lib', __DIR__.'/../vendor/PHPPdf/lib/vendor/Imagine/lib'),
'Zend' => __DIR__.'/../vendor/PHPPdf/lib/vendor/Zend/library',
'ZendPdf' => __DIR__.'/../vendor/PHPPdf/lib/vendor/ZendPdf/library',

AppKernel.php:

... new Ps\PdfBundle\PsPdfBundle(), ...

I guess all the setting up is correctly configured, as I am not getting any "library not found" nor anything on that way...

So, after all that, I am doing this in the controller:

...
use Ps\PdfBundle\Annotation\Pdf;
...

/**
 * @Pdf()
 * @Route ("/pdf", name="_pdf")
 * @Template()
 */
public function generateInvoicePDFAction($name = 'Pedro')
{
    return $this->render('AcmeStoreBundle:Shop:generateInvoice.pdf.twig', array(
        'name' => $name,
    ));
}

And having this twig file:

<pdf>
    <dynamic-page>
        Hello {{ name }}!
    </dynamic-page>
</pdf>

Well. Somehow, what I just get in my page is just the normal html generated as if it was a normal Response rendering.

The Pdf() annotation is supposed to give the "special" behavior of creating the PDF file instead of rendering normal HTML.

So, having the above code, when I request the route http://www.mysite.com/*...*/pdf, all what I get is the following HTML rendered:

<pdf>
    <dynamic-page>
        Hello Pedro!
    </dynamic-page>
</pdf>

(so a blank HTML page with just the words Hello Pedro! on it.

Any clue? Am I doing anything wrong? Is it mandatory to have the alternative *.html.twig apart from the *.pdf.twig version? I don't think so... :(

© Stack Overflow or respective owner

Related posts about php

Related posts about symfony2