1

When I go to /fileDownload I receive a 500 Internal Server Error - RuntimeException:

The process stopped because of a "0" signal.

Controller Action:

public function fileAction()
{
    $html = $this->render('MyBundle:Downloads:file.html.twig', array(
    'fileNumber'  => '1234'
    ));

    return new Response(
        $this->get('knp_snappy.pdf')->getOutputFromHtml($html),
        200,
        array(
            'Content-Type'          => 'application/pdf',
            'Content-Disposition'   => 'attachment; filename="file.pdf"'
        )
    );
}

I've used terminal commands for WKHTMLTOPDF and it has successfully generated the PDF. It just will not work in Symfony2 app.

In my config.yml:

knp_snappy:
    pdf:
        enabled:    true
        binary:     /usr/local/bin/wkhtmltopdf
        options:    []
McGarnagle
  • 101,349
  • 31
  • 229
  • 260
Xavier
  • 107
  • 2
  • 9

5 Answers5

0

I'm assuming Symfony is issuing an exec() at some stage. You need to get the exact command line error returned. The fact it works for you in a terminal session doesn't necessarily mean it will work when a different user/process is running it.

Check permissions on wkhtmltopdf that apache or whoever is running your web server has access to run the command.

Also, check this question out wkhtmltopdf: cannot connect to X server and also the first post here: http://geekisland.org/index.php?m=05&y=11&entry=entry110518-114630

X Server is required to run certain builds of wkhtmltopdf and it is not present when running via cron or from within an apache process. If this is the case you need to use the bash wrapper in the first link above.

Community
  • 1
  • 1
Niall
  • 425
  • 6
  • 14
0

Be sure that wkhtmltopdf is indeed in the folder you specify, with correct permissions: /usr/local/bin/wkhtmltopdf

I am successfully using KNP Snappy Bundle with Symfony 2.0, try using RenderView instead of render when generating the html (check my code that is working):

Controller:

$html = $this->renderView('YOPYourOwnPoetBundle:thePoet:poemPDF.html.twig', array(
                'poem'  => $customizedPoem,
                'fontType' => $fontType,
                'fontSize' => $formData['fontSize'],
                'fontWeight' => $fontWeight,
                'fontStyle' => $fontStyle,
            ));
return new Response(
                $this->get('knp_snappy.pdf')->getOutputFromHtml($html),
                200,
                array(
                    'Content-Type'          => 'application/pdf',
                    'Content-Disposition'   => 'attachment; filename="'.$session->get('poemTitle').'.pdf"',
                )
            );
fkoessler
  • 6,932
  • 11
  • 60
  • 92
  • Still does not work. Are you on a local mac? Did you have to install anything else besides the KNP bundle & wkhtmltopdf? – Xavier Oct 30 '12 at 17:48
  • No I don't think I had to install anything else, it's been a long time though. I have it running on an Ubuntu Server. Maybe you are having a permission issue? I have put the library in my vendor directory: vendor/wkhtmltoimage/bin/wkhtmltopdf. I'm not sure it will change anything though... – fkoessler Oct 31 '12 at 01:49
0

I had this same issue and i finally solved it, my advice is if you installed the wkhtmltopdf lib from your OS repos then remove it, and download the static version from the google code website, and don't use version 11rc, use the version 9 static lib, it's the one that worked with me.

http://code.google.com/p/wkhtmltopdf/downloads/list

Mohammad AbuShady
  • 40,884
  • 11
  • 78
  • 89
0

It looks like the selinux is blocking your command, I had the same issue once but I solved it by disabling the SELinux and now I'm able to generate the pdf file using wkhtmltopdf+php.

exec("/usr/local/bin/wkhtmltopdf http://www.google.com /var/www/html/google.pdf");

To disable selinux run setenforce 0, try again and see if it works. Re-enable it with setenforce 1

But disabling selinux is not the best solution for this, you need to extend it instead using audit2allow, it will automatically create a custom policy module that will resolve this issue, First install audit2allo if not already installed

yum -y install policycoreutils-python
grep httpd_t /var/log/audit/audit.log | audit2allow -m httpdlocal > httpd.te
checkmodule -M -m -o httpdlocal.mod httpd.te
semodule_package -o httpdlocal.pp -m httpdlocal.mod
semodule -i httpdlocal.pp

try again and see if it works

benaich
  • 912
  • 11
  • 29
0

I experienced the same issue on same scenario with wkhtmltopdf. And I got rid of with the following command:

setsebool httpd_execmem on