Search code examples
phplaravelpdfsnappy

error to print pdf in linux with Snappy PDF


i have a problem with the configuration file in config/snappy.php programming in windows i have this configuration, work really good, the problem is when i put the code in my production app in linux, the configuration is not the same....


return array(
    'pdf' => array(
        'enabled' => true,
       'binary' => '"C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe"',       
       //'binary' => '"C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf"',
        'options' => array(),
    ),
    'image' => array(
        'enabled' => true,
        'binary' => '"C:\Program Files\wkhtmltopdf\bin\wkhtmltoimage.exe"',
        'options' => array(),
    ),
);

I try with this configuration but is not working...

'binary' => '/usr/local/bin/wkhtmltopdf-amd64',

and with this line too

'binary' => base_path('vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64'),

but is not working...

have ubuntu

php 7.0

laravel 5.5

Thanks


Solution

  • first you have to install snappy dependancy using composer require knplabs/knp-snappy (please see this repository)

    then the binaries will be at /vendor/h4cc/wkhtmltoimage-amd64/bin and /vendor/h4cc/wkhtmltopdf-amd64/bin

    Move the binaries to a path that is not in a synced folder, for example:

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

    and make it executable:

    chmod +x /usr/local/bin/wkhtmltoimage-amd64 chmod +x /usr/local/bin/wkhtmltopdf-amd64

    This will prevent the error 126.

    Please see and go through the documentation here

    If you followed the vagrant steps, the line should look like

    'binary' => '/usr/local/bin/wkhtmltopdf-amd64',