[英]how to solve laravel/snappy error code 127?
Recently i have updated laravel to version 7 and when i want to download the pdf from laravel/snappy i get this error :最近我已将 laravel 更新到第 7 版,当我想从 laravel/snappy 下载 pdf 时出现此错误:
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最好的选择应该是安装 wkhtmltopdf 作为作曲家依赖安装这个
And after in config for an example config/snappy.php然后在 config 示例 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).如果您在 Linux 或 macOS 上工作,请运行$ which wkhtmltopdf
以查找二进制文件在您的计算机上的存储位置(前提是您已安装该软件)。
Then, make sure config/snappy.php
configuration points to that binary, see:然后,确保config/snappy.php
配置指向该二进制文件,请参阅:
'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
.如果您将二进制路径存储在.env
文件中,您可能需要使用php artisan config:clear
缓存。
I'm using laradock and php 7.4 and got the same problem.我正在使用 laradock 和 php 7.4 并遇到了同样的问题。 Just replace the code below in laradock\php-fpm\Dockerfile只需在 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:在 Ubuntu 22.04/20.04 中,您可以通过以下方式轻松安装它:
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 .问题是我正在使用 utf-8 进行波斯语解析,而 wkhtmltopdf 的唯一版本是 0.12.16-1,因此负责保存 pdf 的二进制目录在新版本中是不同的。
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总之,如果您使用 wkhtmltopdf 并收到此错误,您应该更改 nginx(或您选择的 Web 服务器)中的二进制目录以使其正常工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.