barryvdh / laravel-snappy

Laravel Snappy PDF
MIT License
2.59k stars 289 forks source link

Mac & Composer Install - The exit status code '127' says something went wrong: stderr: #523

Closed kinger251285 closed 6 months ago

kinger251285 commented 6 months ago

After a recommendation from someone in the laravel community i installed this package to a brand new Laravel 10.10 project

I've installed wkhtmltopdf as a composer package.

I've tried the i386, amd-64 and the amd-64-osx (seperate install) composer packages and get the same error everytime as below no matter which version i set in my config file:

The exit status code '127' says something went wrong: stderr: "sh: /Users/me/my-folder: No such file or directory " stdout: "" command: /Users/me/my-folder/Laravel/project/vendor/bin/wkhtmltopdf-amd64-osx --lowquality '/var/tmp/knp_snappy658425505c01b9.53364468.html' '/var/tmp/knp_snappy658425505c1a63.86576237.pdf'.

config/snappy.php (I'm aware the paths are different for pfd & image just giving examples of configs i've tried).

    'pdf' => [
        'enabled' => true,
        'binary'  => 'vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64',        
        'timeout' => false,
        'options' => [],
        'env'     => [],
    ],

    'image' => [
        'enabled' => true,
        'binary'  => base_path('vendor/h4cc/wkhtmltoimage-i386/bin/wkhtmltoimage-i386'),  
        'timeout' => false,
        'options' => [],
        'env'     => [],
    ],
$data = [];
$pdf = PDF::loadView('pdf.accountApplication', $data);
return `$pdf->download('some-company-account-application.pdf');
kinger251285 commented 6 months ago

So on mac you need to use the osx binaries - i used this instead of the recommended ones (locally on mac only):

https://github.com/profburial/wkhtmltopdf-binaries-osx

This still didn't work because when using base_path() and folders that contain spaces this gets escaped at the first space so cannot find the correct vendor package.

I added the path manually as below to the config rather than using base_path:

'pdf' => [
        'enabled' => true,
        'binary'  => '/Users/me/Some\ Folder\ Name/Laravel/Project/vendor/bin/wkhtmltopdf-amd64-osx',        
        'timeout' => false,
        'options' => [],
        'env'     => [],
    ],

    'image' => [
        'enabled' => true,
        'binary'  => '/Users/me/Some\ Folder\ Name/Laravel/Project/vendor/bin/wkhtmltoimage-amd64-osx',
        'timeout' => false,
        'options' => [],
        'env'     => [],
    ],
kinger251285 commented 6 months ago

Closed