尝试使用 Snappy(wkhtmltopdf 包装器)生成 pdf

发布于 2024-10-17 20:10:56 字数 1170 浏览 5 评论 0原文

我正在尝试通过以下代码使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

云巢 2024-10-24 20:10:56

我建议您首先查看 $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.

话少情深 2024-10-24 20:10:56

使用 $snappy->generate

$snappy->generateFromHtml($htmlstring, 'path/to/save/file')

use $snappy->generate

or

$snappy->generateFromHtml($htmlstring, 'path/to/save/file')

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文