RVandersteen
RVandersteen

Reputation: 2137

Symfony - TCPdf - Unable to find template

I'm stuck with an annoying error with TCPdf and Symfony:

request.CRITICAL: Uncaught PHP Exception InvalidArgumentException: "Unable to find template "" (looked into: /Applications/MAMP/htdocs/api/app/Resources/views)." at /Applications/MAMP/htdocs/api/vendor/symfony/symfony/src/Symfony/Bridge/Twig/TwigEngine.php line 128 {"exception":"[object] (InvalidArgumentException(code: 0): Unable to find template \"\" (looked into: /Applications/MAMP/htdocs/api/app/Resources/views). at /Applications/MAMP/htdocs/api/vendor/symfony/symfony/src/Symfony/Bridge/Twig/TwigEngine.php:128, Twig_Error_Loader(code: 0): Unable to find template \"\" (looked into: /Applications/MAMP/htdocs/api/app/Resources/views). at /Applications/MAMP/htdocs/api/vendor/twig/twig/lib/Twig/Loader/Filesystem.php:215)"} []

In my controller I just create a pdf and output it:

public function pdfAction()
{
    $pdf = ...;
    ...
    $pdf->output();
}

My best guess is that Symfony is trying to return a Response (but the output already gave one) and thus the error. However I cannot find how I should resolve this in Symfony. Any help or tips are welcome.

PS: The pdf works perfectly, only monologger that is spamming me with errors ..

For future reference:

This is how I solved it in the end:

$pdf->Output('output.pdf', 'I');
return new Response();

I tried many different options but this is the only one that doesn't trigger that error.

Upvotes: 0

Views: 908

Answers (1)

6be709c0
6be709c0

Reputation: 8461

With Symfony you need to return response as array.

Maybe this piece of code works:

$pdfOutput = $pdf->output();

return array('pdfOutput' => $pdfOutput); // or just try to return $pdf;

// If you don't use annotation : 
return $this->render('your-template.html.twig', array(
    'pdfOutput' => $pdfOutput
));

And in your template, if you want to result some things, your template looks like that :

{{ dump(pdfOutput) }}

EDIT

Try with a path as arguments

$pdf->Output("output.pdf", 'I');

TCPDF output doc

Upvotes: 1

Related Questions