Recently i have updated laravel to version 7 and when i want to download the pdf from laravel/snappy i get this error :
The exit status code '127' says something went wrong:\nstderr: \"sh: 1: /usr/local/bin/wkhtmltopdf: not found\n\"\nstdout: \"\"\ncommand: /usr/local/bin/wkhtmltopdf --lowquality --orientation 'landscape' --page-size 'a4' --encoding 'utf-8' '/tmp/knp_snappy5fa9279006a045.56009440.html' '/tmp/knp_snappy5fa9279006aaf0.09066361.pdf
original code generating this error :
$data['company'] = $this->user->company->toArray();
$data['departments'] = $this->user->company->departments->toArray();
$this->prepareText($data);
/* @var $pdf PdfWrapper */
$pdf = App::make('snappy.pdf.wrapper');
$pdf->loadView('ticket.index', compact('data'))
->setOrientation('landscape')
->setOption('encoding', 'utf-8')
->setPaper('a4');
return $pdf->inline(sprintf('Employee-Report-(%s).pdf', Jalalian::forge('now')
->format('Y-m-d')));
The best option should be install wkhtmltopdf as an composer dependency install this
And after in config for an example config/snappy.php
'pdf' => [
'enabled' => true,
'binary' => env(
'WKHTML_PDF_BINARY',
base_path('vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64'),
),
'timeout' => false,
'options' => [],
'env' => [],
],
'image' => [
'enabled' => true,
'binary' => env(
'WKHTML_IMG_BINARY',
base_path('vendor/h4cc/wkhtmltoimage-amd64/bin/wkhtmltoimage-amd64'),
),
'timeout' => false,
'options' => [],
'env' => [],
],
If you are working on Linux or macOS, run $ which wkhtmltopdf
to find where the binary is stored on your machine (provided that you've installed the software).
Then, make sure config/snappy.php
configuration points to that binary, see:
'pdf' => [
'enabled' => true,
'binary' => env('WKHTML_PDF_BINARY', '/usr/local/bin/wkhtmltopdf'),
'timeout' => false,
'options' => [],
'env' => [],
],
'image' => [
'enabled' => true,
'binary' => env('WKHTML_IMG_BINARY', '/usr/local/bin/wkhtmltoimage'),
'timeout' => false,
'options' => [],
'env' => [],
],
If you store your binary paths in .env
file, you may need to clear the cache with php artisan config:clear
.
I'm using laradock and php 7.4 and got the same problem. Just replace the code below in laradock\php-fpm\Dockerfile
ARG INSTALL_WKHTMLTOPDF=true
RUN if [ ${INSTALL_WKHTMLTOPDF} = true ]; then \
apt-get install -y \
libxrender1 \
libfontconfig1 \
libx11-dev \
libjpeg62 \
libxtst6 \
fontconfig \
libjpeg62-turbo \
xfonts-base \
xfonts-75dpi \
wget \
&& wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.stretch_amd64.deb -O /usr/local/bin/wkhtmltopdf \
&& chmod +x /usr/local/bin/wkhtmltopdf \
&& dpkg -i --force-depends /usr/local/bin/wkhtmltopdf \
&& apt -f install \
;fi
Then,
docker-compose build php-fpm workspace
In Ubuntu 22.04/20.04 you can easily install it through:
wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.focal_amd64.deb
sudo apt install ./wkhtmltox_0.12.6-1.focal_amd64.deb
I finally got the answer . Problem is that i am using utf-8 for persian parsing and the only version of wkhtmltopdf which is working with that is 0.12.16-1 and as a result the binary directory which is responsible for saving the pdf is different in newer versions .
In conclusion, if you are using wkhtmltopdf and getting this error you should change the binary directory in your nginx (or your chosen web server ) to make it work
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.