Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2 PDF Generator Bundle [closed]

Tags:

pdf

symfony

I am looking for a PDF generator bundle that is easy to use and that does not require wkhtmltopdf as my shared hosting server does not support this.

I have tried https://github.com/psliwa/PdfBundle, but if I follow the documentation I simply get a response on the screen (no PDF generated). While there is a solution for this in this question, this solution seems overly complex.

I have also looked at ioalessio/IoTcpdfBundle, which seems straight-forward enough to use, but does not have a composer install and my web server does not support vendor install.

I have also tried stedekay/SpraedPDFGeneratorBundle, but this just plain errors complaining about not finding Java.

While whiteoctober/WhiteOctoberTCPDFBundle might be able to work, this just creates a TCPDF object that one has to work with further and the documentation is not very encompassing.

Any suggestions (or advice on how to get any of the mentioned bundles working) will be greatly appreciated.

like image 839
Magnanimity Avatar asked Jan 12 '23 03:01

Magnanimity


1 Answers

I use SpraedPDFGeneratorBundle and I install it from https://github.com/stedekay/SpraedPDFGeneratorBundle using Composer to activate it. I activated in the AppKernel new Spraed\PDFGeneratorBundle\SpraedPDFGeneratorBundle().

Finally I executed the command php composer.phar update and in my controller I put this code:

 $html = $this->renderView('MyappJournalBundle:Default:index1.html.twig');
    $pdfGenerator = $this->get('spraed.pdf.generator');

    return new Response($pdfGenerator->generatePDF($html),
                    200,
                    array(
                        'Content-Type' => 'application/pdf',
                        'Content-Disposition' => 'inline; filename="out.pdf"'
                    )
    );

and it worked for me!

like image 63
Ghassen Avatar answered Jan 16 '23 22:01

Ghassen