You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Laravel 5.6使用barryvdh/snappy在Windows生成PDF遇错误求助

解决Laravel 5.6中Barryvdh/snappy生成PDF的exit status code 1错误

你遇到的这个问题核心原因很明确:在Windows环境下误用了Linux版本的wkhtmltopdf二进制文件——你配置里的h4cc/wkhtmltopdf-amd64是专门给64位Linux系统用的,Windows系统根本没法运行它,所以才会抛出exit status 1的报错。

下面是一步步的修复方案:

1. 替换为Windows兼容的wkhtmltopdf包

先卸载当前的Linux版本依赖:

composer remove h4cc/wkhtmltopdf-amd64

然后根据你的Windows系统位数,安装对应版本的包:

  • 64位系统:
    composer require h4cc/wkhtmltopdf-windows-amd64
    
  • 32位系统:
    composer require h4cc/wkhtmltopdf-windows-i386
    

2. 更新配置文件中的二进制路径

打开config/snappy.php,把pdf数组里的binary路径改成Windows版本的可执行文件路径(注意要加.exe后缀):
比如64位系统的配置应该是:

'pdf' => array(
    'enabled' => true,
    'binary' => base_path('vendor/h4cc/wkhtmltopdf-windows-amd64/bin/wkhtmltopdf.exe'),
    'timeout' => 30,
    'options' => array(),
    'env' => array('PATH' => env('PATH')),
)

3. 额外排查项

  • 手动测试二进制文件:直接去配置的路径下双击wkhtmltopdf.exe,如果弹出缺少VC运行库的提示,就安装对应的微软VC Redistributable运行库。
  • 确认视图文件pdf.blade.php存在且语法正确,避免因为视图渲染失败间接导致PDF生成报错。

做完以上步骤后,重新运行你的控制器代码,应该就能正常生成并下载PDF了。

内容的提问来源于stack exchange,提问作者Naveed Sheriffdeen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 04:01:34