Trance Code
Trance Code

Reputation: 157

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

Upvotes: 1

Views: 2135

Answers (3)

Trance Code
Trance Code

Reputation: 157

this is the solution

$ composer require h4cc/wkhtmltopdf-amd64 0.12.x $ composer require h4cc/wkhtmltoimage-amd64 0.12.x

my error was put this comand in the project folder, but is in the root...

thanks

Upvotes: 0

Ajay Kulkarni
Ajay Kulkarni

Reputation: 3039

  1. If you want to download wkhtmltopdf and wkhtmltoimage with composer you add to composer.json:

    $ composer require h4cc/wkhtmltopdf-i386 0.12.x
    $ composer require h4cc/wkhtmltoimage-i386 0.12.x

or this if you are in 64 bit based system:

$ composer require h4cc/wkhtmltopdf-amd64 0.12.x
$ composer require h4cc/wkhtmltoimage-amd64 0.12.x  

You should be able to use it from cmd/terminal now.
You can use it in PHP like this:

<?php

use Knp\Snappy\Pdf;

$myProjectDirectory = '/path/to/my/project';

$snappy = new Pdf($myProjectDirectory . '/vendor/h4cc/wkhtmltopdf-i386/bin/wkhtmltopdf-i386');

// or

$snappy = new Pdf($myProjectDirectory . '/vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64');  

If you're a vagrant user, you should move binaries to unsynced folder by using mv command. Then make exdcutable by using chmod +x command.
You can add requirement like this:

composer require barryvdh/laravel-snappy  

Then update composer by using this command

php composer.phar update  

You can find basic usage here...

Upvotes: 1

Unni K S
Unni K S

Reputation: 375

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

Upvotes: 2

Related Questions