我想从包含图像的树枝视图中生成一个PDF文件。这是我的控制器:动作:
public function generatePdfAction(Request $request)
{
// initialize the $emp variable
$html = $this->renderView('PFEEmployeesBundle:Employee:view.html.twig',
array('employee'=> $employee)
);
return new Response(
$this->get('knp_snappy.pdf')->getOutputFromHtml($html),
200,
array(
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'attachment; filename="file.pdf"'
)
);
}
这是config.yml中的配置:
knp_snappy:
pdf:
enabled: true
binary: ""C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe""
options: []
image:
enabled: true
binary: ""C:\Program Files\wkhtmltopdf\bin\wkhtmltoimage.exe""
options: []
代码生成一个包括CSS的PDF文件。我有两个问题,第一个是PDF文件中未显示的图像。第二个是如何渲染整个视图,而是小树枝视图的一个块(视图扩展了另一个)。
我有两个问题,第一个是未显示的图像
所有资产都必须在绝对URL中调用:
<img src="{{ asset('images/logo.png', absolute=true) }}" alt="Symfony!" />
尝试这个。
<img src="{{ app.request.scheme ~'://'~ src="{{ asset('images/logo.png', absolute=true) }}" alt="Symfony!" />