在symfony应用程序中,我使用knp_snappy生成PDF:
return new Response(
$this->get('knp_snappy.pdf')->getOutput($url),
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)java version "1.7.0_79"
[more here ... cut for clarity]
OpenJDK Runtime Environment (IcedTea 2.5.6) (7u79-2.5.6-0ubuntu1.14.04.1)
OpenJDK 64-Bit Server VM (build 24.79-b02, mixed mode)
(wkhtmltopdf:12934): Gtk-WARNING **: cannot open display:
"
stdout: ""
command: wkhtmltopdf --lowquality 'http://symfony.dev/app_dev.php/application/reporter/674/inventory' '/tmp/knp_snappy5643248854b563.21161953.pdf'.
请注意:
$url
确实有效并且是绝对URL(因为它包含CSS的链接)。$this->get('knp_snappy.pdf')->getOutputFromHtml($html)
代替$this->get('knp_snappy.pdf')->getOutput($url)
这一切都很好,但后来我无法加载CSS(这是正常的行为)