0

I use KnpSnappyBundle to generate PDF in my Symfony2 application. It works fine on my local wamp with the configuration :

binary:     "\"C:\\Program Files\\wkhtmltopdf\\bin\\wkhtmltopdf.exe\""

I trying with the application, but with a folder with wkhtmltox at the root with the configuration :

binary:     %kernel.root_dir%/../wkhtmltox/bin/wkhtmltopdf

It doesn't work. It get the following message :

The exit status code '127' says something went wrong:
stderr: "sh: wkhtmltox/bin/wkhtmltopdf: No such file or directory
"
stdout: ""
command: wkhtmltox/bin/wkhtmltopdf --lowquality 
'/tmp/knp_snappy595a4fa89a6676.24945632.html' 
'/tmp/knp_snappy595a4fa89a6a59.72414975.pdf'.

I'm using a OVH's webhosting server.

Gilles Lengy
  • 75
  • 1
  • 10

2 Answers2

3

You could try to install wkhtmltopdf from https://github.com/h4cc/wkhtmltopdf-amd64

Require the package for i386 with:

composer require h4cc/wkhtmltopdf-i386 "0.12.3"

And for amd64 with:

composer require h4cc/wkhtmltopdf-amd64 "0.12.3"

The binary will then be located at:

vendor/h4cc/wkhtmltopdf-i386/bin/wkhtmltopdf-i386

or

vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64

For latter, services.yml will look like this:

knp_snappy:
    pdf:
        enabled:    true
        binary:     '%kernel.root_dir%/../vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64'
        options:    []

    temporary_folder: '%kernel.cache_dir%/snappy'

By installing it in the vendor folder you will no more be dependent on the machine you're running your app.

Matko Đipalo
  • 1,676
  • 1
  • 11
  • 23
  • Thamk you for your help. Now I Have the followine message : The exit status code '126' says something went wrong: stderr: "sh: /home/procontakq/Configurateur/app/../vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64: Permission denied... – Gilles Lengy Jul 04 '17 at 13:42
  • Found an answer here : https://stackoverflow.com/questions/36065028/permission-denied-with-wkhtmltopdf?rq=1 – Gilles Lengy Jul 05 '17 at 12:45
  • I am glad that you find an answer for permission issues. I was in a rush so I couldn't analyze your problem. Is everything working now? – Matko Đipalo Jul 05 '17 at 12:53
  • No. Is not working... Sorry for the late answer. I was busy with something else... – Gilles Lengy Sep 25 '17 at 13:29
  • I found out that the required lib are not all installed ont hes shared server. There is nothing I can do with it.... – Gilles Lengy Oct 09 '17 at 08:33
0

I found this post via Googling, and so am posting my solution in case it helps someone.

The command being run by KNP Snappy in my case was vendor/h4cc/wkhtmltopdf-i386/bin/wkhtmltopdf-i386 and I got the same "no such file or directory" error from it.

I was confused, because I could see this file, and it was executable:

$ ls -al vendor/h4cc/wkhtmltopdf-i386/bin/wkhtmltopdf-i386 
-rwxr-xr-x 1 1000 1000 41424004 Nov  7 09:07 vendor/h4cc/wkhtmltopdf-i386/bin/wkhtmltopdf-i386

But when I tried to run it...

$ vendor/h4cc/wkhtmltopdf-i386/bin/wkhtmltopdf-i386 
-bash: vendor/h4cc/wkhtmltopdf-i386/bin/wkhtmltopdf-i386: No such file or directory

I was confused because it appeared that the error was that the executable didn't exist, and it clearly did exist.

In fact, the problem was that I was trying to use the 32-bit version of the executable, and my machine was 64-bit:

$uname -a
Linux mybox 3.2.0-4-amd64 #1 SMP Debian 3.2.54-2 x86_64 GNU/Linux

(see the amd64 part)

So I had to update this bit in config.yml:

knp_snappy:
    pdf:
        binary: # this was the path to the 32-bit executable; I had to update it to use the 64-bit version.
Sam
  • 5,997
  • 5
  • 46
  • 66