2

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.

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.

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.

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

So wkhtmltopdf have no problems with absolute URLs on localhost !

Thanks

Sami
  • 717
  • 6
  • 28

1 Answers1

2

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

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"

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

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

Works like a charm

Sami
  • 717
  • 6
  • 28