Nicks
Nicks

Reputation: 774

KnpSnappyBundle The exit status code '127' says something went wrong:

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'.

Upvotes: 2

Views: 19663

Answers (5)

Yogesh.galav
Yogesh.galav

Reputation: 285

I replaced the command given in official readme

cp vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64 /usr/local/bin/

with following one

cp vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64 /usr/local/bin/wkhtmltopdf

Upvotes: 0

hemant kumawat
hemant kumawat

Reputation: 131

I Solved Problem, Its happening because system doesn't have installed wkhtmltopdf Plugin. please Follow Links to install this plugin:-

Hope this helps for future endeavors.

Upvotes: 4

yvoloshin
yvoloshin

Reputation: 378

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

Upvotes: 0

Nicks
Nicks

Reputation: 774

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

Upvotes: 0

Tartare2240
Tartare2240

Reputation: 57

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/...

Upvotes: 0

Related Questions