0

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>
4

1 回答 1

0

来自捆绑包的作者:

如果直接使用 $facade 对象,则不需要 Pdf 注释。当您想以隐式方式使用 pdf 呈现时,您应该使用 Pdf 注释。在您的代码中,您应该将样式表 xml 作为 $facade->render(...) 方法的第二个参数传递。

控制器现在读取:

   /**
     * @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'));
    }
于 2013-10-02T15:14:45.627 回答