在KnpSnappyBundle中使用时,选项footer-html返回错误

时间:2015-04-28 12:58:28

标签: symfony footer wkhtmltopdf

我正在尝试使用wkhtmltopdf库和symfony2包装器KnpSnappyBundle构建发票pdf。

我想在wkhtmltopdf选项footer-html的每个页面上添加一个页脚。在命令行中,一切正常,我的pdf已构建,每页都重复一个页脚。但是当我使用捆绑服务时:

$snappy = $this->get('knp_snappy.pdf');
$snappy->setOption('footer-html', 'http://www.google.com');
$content = $snappy->getOutputFromHtml($html);

return new Response(
    $content,
    200,
    array(
        'Content-Type'          => 'application/pdf',
        'Content-Disposition'   => 'attachment; filename="file.pdf"'
    )
);

它会返回错误:

The exit status code '1' says something went wrong:
stderr: "Loading pages (1/6)
[> ] 0%
[======> ] 10%
Error: Failed loading page http://www.google.com (sometimes it will work just to ignore this error with --load-error-handling ignore)
Exit with code 1 due to network error: HostNotFoundError
"
stdout: ""
command: C:\wkhtmltopdf\bin\wkhtmltopdf.exe --lowquality --dpi "300" --margin-bottom "0" --margin-left "0" --margin-right "0" --margin-top "0" --page-size "A4" --background --encoding "utf-8" --footer-html "http://www.google.com" "http://www.google.com" "test.pdf".

是否已经成功使用了KnpSnappyBundle的footer-html选项?

1 个答案:

答案 0 :(得分:0)

我认为问题在于这一行:

$snappy->setOption('footer-html', 'http://www.google.com');

setOption()方法中的第二个参数是在本地文件系统上查找html文件。正如它目前所写,它会尝试将Google主页作为页脚包含在pdf的每个页面上。尝试这样的事情:

$snappy->setOption('footer-html', 'path/to/footer.html');
$snappy->getOutput('https://google.com');

请注意,.html很重要,非.phtml等非标准扩展名会导致错误。

相关问题