【问题标题】:Snappy footer generate a weird margin proportional to its sizeSnappy 页脚生成与其大小成比例的奇怪边距
【发布时间】:2018-09-27 13:21:27
【问题描述】:

首先,让我向您展示导致错误发生的一段代码。

这是我的页脚代码:

<!doctype html>
<html>
<head>
    <meta charset="UTF-8">

</head>
<body>
<div style="height: 1rem; background-color: #1C440C">

    <span>Hello world</span>

</div>
</body>
</html>

主页:

<!doctype html>
<html>
<head>
    <meta charset="UTF-8">

</head>
<body>


    Hello world page

</body>
</html>

还有控制器:

   /**
     * @Route("/path", name="myurl")
     */
    public function toPdf()
    {
        $html = $this->renderView('pdf/page.html.twig');
        $footer = $this->renderView('pdf/footer2_pdf.html.twig');
        return new Response(
            $this->get('knp_snappy.pdf')->getOutputFromHtml($html, array(
                'footer-html' => $footer
            )),
            200,
            array(
                'Content-Type'          => 'application/pdf',
                'Content-Disposition'   => 'attachment; filename="file.pdf"'
            )
        );

我将页脚高度设置为 1(就像在代码示例中一样),我得到了这种 pdf 页脚:

“hello world”和页面的bot之间的距离看起来像pdf的默认边距,所以看起来还可以。

然后,如果我将高度更改为 5rem 以获得更大的页脚,我会得到:

页脚变大了,但页脚和页尾之间的边距却像疯了似的增加了。我真的不明白为什么。

感谢您的阅读,如果您知道答案,请随时回答。

【问题讨论】:

  • 你试过这个答案来强制固定边距吗? stackoverflow.com/questions/35995847/…
  • 我尝试使用@page{margin-bottom: 50} 设置边距,但效果不佳。这种方式与 snappy 选项一起完成了这项工作。

标签: symfony pdf pdf-generation wkhtmltopdf knp-snappy


【解决方案1】:

为了将来参考,只需使用此解决方案设置底部边距: pdf page margins with snappy and symfony2 干杯!

【讨论】:

    猜你喜欢
    • 2014-02-10
    • 1970-01-01
    • 2015-09-13
    • 2018-04-01
    • 1970-01-01
    • 2014-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多