下面是我添加页眉和页脚以生成pdf的代码,我不知道我在做错了。请帮忙!
$html = $this->renderView('CoreBundle:PdfGenerator:generate.html.twig', array(
'userId' => $userId,
));
$snappy = $this->get('knp_snappy.pdf');
$snappy->setOption('header-html', $this->container->get('templating.helper.assets')->getUrl('bundles/core/pdfHtml/header.html'));
$snappy->setOption('footer-html', $this->container->get('templating.helper.assets')->getUrl('bundles/core/pdfHtml/footer.html'));
//echo $request->getHost().$this->container->get('templating.helper.assets')->getUrl('bundles/core/pdfHtml/header.html'); die();
echo $html; die();
return new Response(
$snappy->getOutputFromHtml($html),
200,
array(
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'attachment; filename="file.pdf"'
)
);
答案 0 :(得分:0)
http://www.michaelperrin.fr/2016/02/17/generating-pdf-files-with-symfony/
按照这个,我让我的东西工作
$header = $this->renderView('FamilyHealthDischargeSummaryBundle:ExportPdf:header.html.twig');
$body = $this->renderView('FamilyHealthDischargeSummaryBundle:ExportPdf:body.html.twig', $data);
$snappy = $this->get('knp_snappy.pdf');
$snappy->setOption('header-html', $header);
return new Response(
$snappy->getOutputFromHtml($body), 200,
[
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'attachment; filename=' . $file2 . '.pdf',
]
);
}