KnpLabs / snappy

PHP library allowing thumbnail, snapshot or PDF generation from a url or a html page. Wrapper for wkhtmltopdf/wkhtmltoimage

Home Page:https://knplabs.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Not working with Codeigniter 4

WeTruck opened this issue · comments

Hi,

I've installed:

$ composer require knplabs/knp-snappy
$ composer require h4cc/wkhtmltopdf-i386 0.12.x
$ composer require h4cc/wkhtmltopdf-amd64 0.12.x

This is my code:

require_once(APPPATH . "ThirdParty/knp-snappy/vendor/autoload.php");
$snappy = new Pdf(APPPATH . "ThirdParty/knp-snappy/vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64");
$snappy->setOption('cover', view("my_pdf_html_file"));

header('Content-Type: application/pdf');
echo $snappy->getOutput('http://www.github.com');

I'm getting this with this code:
image

On the other hand, if I add,
$snappy->generateFromHtml('<h1>Bill</h1><p>You owe me money, dude.</p>', '/tmp/bill-123.pdf');
instead of,
$snappy->setOption('cover', view("my_pdf_html_file"));

It's showing this,

RuntimeException #1
The exit status code '1' says something went wrong:
stderr: "'my_app_location\app\ThirdParty/knp-snappy/vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64' is not recognized as an internal or external command,
operable program or batch file.
"
stdout: ""
command: my_app_location\app\ThirdParty/knp-snappy/vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64 --lowquality "C:\Users\my_user_name\AppData\Local\Temp\knp_snappy612dc5e78d5fb0.99757512.html" "/tmp/bill-123.pdf".

I'm using Codeigniter 4.
Please help. Thanks.

Hello,
I'm not familiar with CodeIgniter but the error seems pretty clear stderr: "'my_app_location\app\ThirdParty/knp-snappy/vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64' is not recognized as an internal or external command, operable program or batch file..
I would suggest you to check if the wkhtmltopdf binary it's really there (at my_app_location\app\ThirdParty/knp-snappy/vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64) and that your PHP process user has all the rights to execute it.
Have you tried to run wkhtmltopdf manually? Does it works?