我在KnpSnappy Bundle文档中遗漏了一些东西。 :(如何使用Symfony和KnpSnappy将我的pdf保存到服务器。我不希望我的pdf下载到浏览器。我希望它保存到服务器。请帮助!非常感谢。
Server Path: $pdfFolder = $_SERVER['DOCUMENT_ROOT'].'/symfonydev/app/Resources/account_assets/'.$account_id.'/pdf/';
return new Response(
$this->get('knp_snappy.pdf')->getOutputFromHtml($content),
200,
array(
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'attachment; filename="'.$pdfFolder.''.strtotime('now').'.pdf"'
)
);
答案 0 :(得分:3)
从documentation可以看出,您需要使用其他功能:
$this->get('knp_snappy.pdf')->generateFromHtml($content, $pdfFolder . time() . '.pdf';
如您所见,我已将strtotime('now')
替换为time()
。它会更快。
答案 1 :(得分:2)
此行生成PDF ...
$this->get('knp_snappy.pdf')->getOutputFromHtml($content)
因此,您可以使用file_put_contents将 getOutputFromHtml($ content)的结果写入文件系统。