[英]Symfony: Use stylesheet with PdfBundle
In an implementation of PdfBundle , adding a stylesheet to the Pdf() annotation neither throws an error or is used. 在PdfBundle的实现中,将样式表添加到Pdf()批注既不会引发错误,也不会被使用。 The page rendered is a default 8.5 x 11, not the expected 5 x 8. Replacing the stylesheet file name with random characters does not elicit an error.
呈现的页面默认为8.5 x 11,而不是预期的5 x8。用随机字符替换样式表文件名不会引发错误。 Is other configuration required to take advantage of a stylesheet?
要使用样式表是否需要其他配置?
/**
* @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'));
}
<pdf>
<page id="card">
...
</page>
</pdf>
<stylesheet>
<page id="card" page-size="8in:5in" margin=".5in" font-size="12">
</page>
</stylesheet>
From the author of the bundle: 来自捆绑包的作者:
If you use $facade object directly, Pdf annotation is unnecessary. 如果直接使用$ facade对象,则不需要Pdf批注。 You should use Pdf annotation when you want to use pdf rendering in implicit way.
如果要隐式使用pdf渲染,则应使用Pdf批注。 In you code you should pass stylesheet xml as second argument of $facade->render(...) method.
在代码中,应将样式表xml作为$ facade-> render(...)方法的第二个参数传递。
Controller now reads: 控制器现在读取:
/**
* @Route("/card")
*/
public function cardAction() {
$em = $this->getDoctrine()->getManager();
$household = $em->getRepository('ManaClientBundle:Household')->find(8607);
$stylesheetXml = $this->renderView('ManaClientBundle:Test:pdfstyle.xml.twig', array());
$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, $stylesheetXml);
return new Response($content, 200, array('content-type' => 'application/pdf'));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.