Symfony2 - PdfBundle not working

Using Symfony2 and PdfBundle to generate dynamically PDF files, I cannot generate files really.

Following the documentation instructions, I installed all the information about the package:

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 think that all the settings are configured correctly, since I do not get any "library not found" and nothing like that ...

So, after all this, I do 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. One way or another, what I just got on my page is regular HTML code, created as if it were a normal Response rendering.

The annotation Pdf()should give a β€œspecial” behavior to create a PDF file instead of rendering regular HTML.

, , http://www.mysite.com/*...*/pdf, , , HTML-:

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

( HTML Hello Pedro! .

? - ? *.html.twig *.pdf.twig? ...: (

+3
2

, .

- , , , . , : http://github.com/psliwa/PdfBundle/blob/master/Controller/ExampleController.php, , . , :

/**
 * @Route ("/generateInvoice", name="_generate_invoice")
 */
public function generateInvoiceAction($name = 'Pedro')
{
    $facade = $this->get('ps_pdf.facade');
    $response = new Response();
    $this->render('AcmeStoreBundle:Shop:generateInvoiceAction.pdf.twig', array("name" => $name), $response);

    $xml = $response->getContent();

    $content = $facade->render($xml);

    return new Response($content, 200, array('content-type' => 'application/pdf'));
}   

: PDF .

+8

, "_" URL-.

$this->render() @Template. @Template _format.

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

/**
 * @Pdf()
 * @Route ("/pdf.{_format}", name="_pdf")
 * @Template()
 */
public function generateInvoicePDFAction($name = 'Pedro')
{
    return array('name' => $name);
}

.

+2

All Articles