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:    []

5 Answers 5

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.

4
  • I only installed WKHTMLTOPDF. I did NOT install anything else. What else do I need to install?
    – Xavier
    Oct 29, 2012 at 18:45
  • You don't need to install anything else if you can run it on the command line.
    – Niall
    Oct 29, 2012 at 21:03
  • Ok. I will try links above. This is local btw. Im on OS X using MAMP
    – Xavier
    Oct 29, 2012 at 21:45
  • Should I have xvfb? I cannot execute the command xvfb-run wkhtmltopdf. I receive xvfb-run: command not found
    – Xavier
    Oct 29, 2012 at 21:51
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"',
                )
            );
2
  • 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, 2012 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, 2012 at 1: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

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

0

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

setsebool httpd_execmem on

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.