在PdfBundle的实现中,向 Pdf() 注释添加样式表既不会引发错误,也不会被使用。呈现的页面是默认的 8.5 x 11,而不是预期的 5 x 8。用随机字符替换样式表文件名不会引发错误。是否需要其他配置才能利用样式表?
控制器:
/**
* @Pdf(stylesheet="ManaClientBundle:Test:pdfstyle.xml.twig",
* @Route("/card")
*/
public function cardAction() {
$em = $this->getDoctrine()->getManager();
$household = $em->getRepository('ManaClientBundle:Household')->find(8607);
$facade = $this->get('ps_pdf.facade');
$response = new Response();
$this->render('ManaClientBundle:Test:card.pdf.twig', array(
'household' => $household,
'date' => date_create(),
), $response);
$xml = $response->getContent();
$content = $facade->render($xml);
return new Response($content, 200, array('content-type' => 'application/pdf'));
}
模板(在.../Resources/views/Test/)
<pdf>
<page id="card">
...
</page>
</pdf>
.../Resources/views/Test/pdfstyle.xml.twig 中的样式表
<stylesheet>
<page id="card" page-size="8in:5in" margin=".5in" font-size="12">
</page>
</stylesheet>