2

我使用“ knp_snappy.pdf ”和 php 来创建 pdf 文件。

$template = $this->renderView('DemoProductBundle:pdf:template.html.twig', array('productData' => $productData));
    $headerTemplate = $this->renderView('DemoProductBundle:pdf:header.html.twig');
    $footerTemplate = $this->renderView('DemoProductBundle:pdf:footer.html.twig');
    $knpSnappy = $this->get('knp_snappy.pdf');
    return new Response($knpSnappy->getOutputFromHtml($template, array(
        'page-size' => 'A4',
        'header-html' => $headerTemplate,
        'footer-html' => $footerTemplate,
        'margin-top' => '0'
    )),
        200,
        array(
            'Content-Type'          => 'application/pdf',
            'Content-Disposition'   => 'attachment; filename="file.pdf"'
        )
    );

页眉内容可以显示在主要内容之上,但页脚内容不能显示。但是如果我用 AI 软件打开这个 pdf 文件,我可以在板子下面找到页脚内容。我的代码有什么问题?另一个问题,如果我尝试创建多个 pdf 文件,主要内容的位置将会改变。

4

0 回答 0