尝试使用 Snappy(wkhtmltopdf 包装器)生成 pdf
我正在尝试通过以下代码使用 snappy 生成 pdf:
$snappy = new SnappyPdf;
$snappy->setExecutable('/usr/bin/wkhtmltopdf');
$snappy->save('http://www.google.com', '/tmp/jander.pdf');
在 apache 日志中我发现:
完成加载页面 (1/6) [>
] 0% [======>
] 10% [==========>
] 18% [============>
] 20% [=============>
] 22% [================>>
] 25% [================>>
] 28% [==================>
] 30% [====================>
] 33% [======================>
] 35% [========================>
] 37% [==========================>>
] 43% [=============================>
] 46% [==================================================== ===========] 100% 计数页数 (2/6) [==================================================== ===========] 对象 1 of 1 解析链接 (4/6) [==================================================== ===========] 对象 1 of 1 加载标头和 页脚 (5/6) 打印页面 (6/6) [> ] 准备中 [==================================================== ===========] 第 1 页(共 1 页)已完成
但未生成 pdf。
有什么想法吗?
哈维尔
I'm trying to generate a pdf using snappy through this code:
$snappy = new SnappyPdf;
$snappy->setExecutable('/usr/bin/wkhtmltopdf');
$snappy->save('http://www.google.com', '/tmp/jander.pdf');
In the apache log i find this:
Done Loading pages (1/6) [>
] 0% [======>
] 10% [==========>
] 18% [============>
] 20% [=============>
] 22% [===============>
] 25% [================>
] 28% [==================>
] 30% [===================>
] 33% [=====================>
] 35% [======================>
] 37% [=========================>
] 43% [===========================>
] 46%
[============================================================] 100% Counting pages (2/6)
[============================================================] Object 1 of 1 Resolving links (4/6)
[============================================================] Object 1 of 1 Loading headers and
footers (5/6) Printing pages (6/6) [>
] Preparing
[============================================================] Page 1 of 1 Done
but the pdf is not generated.
Any idea?
Javier
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议您首先查看
$snappy->save()
的返回值。根据代码,如果输出的PDF会返回true文件已创建且文件不为空。您可能还想检查 代码。尝试在您的服务器上手动执行此代码。
I suggest you start by looking at the return value from
$snappy->save()
. According to the code, it will return true if the outputted PDF file is created and the file is not empty.You might also want to check the output of
$this->buildCommand($url, $path)
on line 37 of the code. Try manually executing this code on your server.使用
$snappy->generate
或
$snappy->generateFromHtml($htmlstring, 'path/to/save/file')
use
$snappy->generate
or
$snappy->generateFromHtml($htmlstring, 'path/to/save/file')