1
votes

I have this error on knpSnappyBundle, i am trying to generate a pdf and then send it by email.

My config look like this :

knp_snappy:
pdf:
    enabled:    true
    binary:     \vendor\h4cc\bin\wkhtmltopdf-amd64\bin\wkhtmltopdf-amd64
    options:    []

Then my controller :

$html = $this->render('AppUserBundle:Emails:envoi-export.html.twig', [
                                      'pointagesList' => $pointagesList,
                                      'user'          => $user,
                                      'date'          => new \DateTime()
                                  ]);
  $filename = sprintf('test-%s.pdf', date('Y-m-d'));

  return new Response(
      $this->get('knp_snappy.pdf')->getOutputFromHtml($html),
      200,
      [
          'Content-Type'        => 'application/pdf',
          'Content-Disposition' => sprintf('attachment; filename="%s"', $filename),
      ]
  );

Full error message :

The exit status code '127' says something went wrong: stderr: "sh: 1: /usr/local/bin/wkhtmltopdf: not found " stdout: "" command: /usr/local/bin/wkhtmltopdf --lowquality '/tmp/knp_snappy57970542debe22.97700913.html' '/tmp/knp_snappy57970542dec563.25042325.pdf'.

3

3 Answers

0
votes

The "binary" chain is the static path of your computer, where you installed wkhtmltopdf. If you installed it via command lines, it should be :

/usr/local/bin/wkhtmltopdf

If you installed it in your vendor repository, it should be there :

/path/to/Symfony/vendor/...
0
votes

I find a working solution.

  • Install wkhtmltopdf in vendor symfony2
  • Install wkhtmltopdf in your virtual machine
  • Install xvfb in your virtual machine
  • Create a wkhtmltopdf.sh file inside your usr/local/bin where wkhtmltopdf is installed with (xvfb-run -a -s "-screen 0 640x480x16" wkhtmltopdf --dpi 150 --zoom 0.6 "$@")
  • In your config.yml use the appropriate path like /usr/local/bin/wkhtmltopdf.sh

I hope it can help someone

0
votes

While trying to figure out same problem, I noticed at another post on this topic that the root directory needs to be specified in the binary location. Adding %kernel.root_dir% solved this error for me. Try this:

binary:     %kernel.root_dir%/../vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64