laravel-snappy pdf生成失败,没有错误

时间:2017-07-27 21:15:36

标签: wkhtmltopdf snappy laravel-snappy

我按照https://github.com/barryvdh/laravel-snappy

上的说明安装了laravel-snappy

安装完成后,我测试了wkhtmltopdf并且它可以工作:

>>> np.vectorize(div)(x, y)
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/usr/lib64/python3.4/site-packages/numpy/lib/function_base.py", line 1811, in __call__
    return self._vectorize_call(func=func, args=vargs)
  File "/usr/lib64/python3.4/site-packages/numpy/lib/function_base.py", line 1880, in _vectorize_call
    outputs = ufunc(*inputs)
  File "<input>", line 2, in div
ZeroDivisionError: division by zero

我可以确认pdf存在:

vagrant@homestead:/usr/local/bin$ /usr/local/bin/wkhtmltopdf google.com /tmp/google.pdf
Loading pages (1/6)
Counting pages (2/6)
Resolving links (4/6)
Loading headers and footers (5/6)
Printing pages (6/6)
Done

这是snappy.php文件的内容:

vagrant@homestead:/tmp$ ls
google.pdf

然而,当我在我的控制器中运行它时,没有任何反应。没有错误消息,也没有生成文件:

return array(


    'pdf' => array(
        'enabled' => true,
        'binary'  => '/usr/local/bin/wkhtmltopdf',
        'timeout' => false,
        'options' => array(),
        'env'     => array(),
    ),
    'image' => array(
        'enabled' => true,
        'binary'  => '/usr/local/bin/wkhtmltoimage',
        'timeout' => false,
        'options' => array(),
        'env'     => array(),
    ),


);

我期待pdf开始下载。可能是什么问题?

1 个答案:

答案 0 :(得分:0)

我通过在没有laravel包装的情况下安装snappy来完成这项工作。然后只需这样做:

use Knp\Snappy\Pdf;

$snappy = new Pdf('/usr/local/bin/wkhtmltopdf');
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename="file.pdf"');
echo $snappy->getOutput('http://www.github.com');

laravel包装器可能存在问题。