KnpSnappyBundle和Symfony 3.4:图像和/或CSS导致超时 [英] KnpSnappyBundle and Symfony 3.4 : images and/or css cause timeout

查看:97
本文介绍了KnpSnappyBundle和Symfony 3.4:图像和/或CSS导致超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在现有的Symfony 3.4项目上安装了KnpSnappyBundle.我已经用HTML树枝测试了PDF生成器,该树枝只有文本,没有图像,没有CSS,没有js:它工作正常.

I've installed KnpSnappyBundle on an existing Symfony 3.4 project. I've tested the PDF generator with a HTML twig with text only, no images, no css, no js : it works fine.

然后我使用绝对URL(我在本地主机上)添加了(到树枝上)图像和Bootstrap.Css文件:PDF生成器显示了一个丑陋的错误:

Then I've added (to the twig) an image and a Bootstrap.Css file using absolute URL (i'm working on localhost): the PDF generator displays an ugly error :

The process "wkhtmltopdf --lowquality '/tmp/knp_snappy5aeb39ad71e767.56551505.html' '/tmp/knp_snappy5aeb39ad71ebf0.62787578.pdf'" exceeded the timeout of 60 seconds.

捆绑商品有什么问题?我正在使用配备8Gb RAM(ubuntu 16.04)的i7笔记本电脑,我认为这不是计算机配置的问题.

What's wrong with the bundle ? I'm using an i7 laptop with 8Gb RAM (ubuntu 16.04), I don't think it's a problem of machine configuration.

更新:我已经从命令行测试了wkhtmltopdf,它确实转换了我的树枝:

UPDATE: I've tested wkhtmltopdf from the command line and it do convert my twig :

wkhtmltopdf http://127.0.0.1:8000/eshop/admin/order/print/2 out.pdf

因此,wkhtmltopdf在本地主机上的绝对URL上没有问题!

So wkhtmltopdf have no problems with absolute URLs on localhost !

谢谢

推荐答案

在此处找到了解决方案: https://github.com/KnpLabs/KnpSnappyBundle/issues/82

Found a solution here : https://github.com/KnpLabs/KnpSnappyBundle/issues/82

当从包中调用wk时,似乎wk无法使用绝对URL查找资产(因此,在shell中执行时),您必须指定一个绝对路径.创建一个细枝全局变量:

It seems like wk is unable to find assets using the absolute URL when called from the bundle (so when executed in shell), you have to specify an absolute path. Create a twig global variable :

twig:
 globals:
  pathToWeb: "%kernel.root_dir%/../web"

然后在树枝中使用新变量而不是asset():

Then in the twig use the new variable instead of asset() :

<link ... href="{{ pathToWeb }}/css/bootstrap.min.css"/>
<img ... src="{{ pathToWeb }}/images/logo.png"/>

像魅力一样工作

这篇关于KnpSnappyBundle和Symfony 3.4:图像和/或CSS导致超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆