【问题标题】:How can i add footer at the bottom of the page wkhtmltopdf如何在页面底部添加页脚 wkhtmltopdf
【发布时间】:2015-05-11 20:27:09
【问题描述】:

我正在使用 wkhtmltopdf 生成报告,现在我遇到了一种情况,我必须在页面底部显示页脚我试图用 css 解决这个问题它适用于简单页面但不适用于我的 wkhtmltopdf 生成页面 这是我的 HTML 代码

<footer id="footer">
    <p>Hello World</p>
</footer>

我的 CSS 是这样的

#footer {
    position:fixed;
    height:50px;
    background-color:red;
    bottom:0px;
    left:0px;
    right:0px;
    margin-bottom:0px;
}

我也尝试过 wkhtmltopdf 页面上给出的这段代码

<script>
    window.onload = function() {
    var vars = {};
    var x = document.location.search.substring(1).split('&');
    for (var i in x) {
        var z = x[i].split('=', 2);
        [z[0]] = unescape(z[1]);
    }

    if current page number == last page number
        if (vars['page'] == vars['topage']) {
            document.querySelectorAll('#footer')[0].textContent = 'extra text  here';
        }
    };
</script>

注意我没有使用 cmd 命令,我使用的是 CodeIgniter。他们有什么选择吗

$this->wkhtmltopdf->setOptions(array(
              'orientation' => 'landscape'
                ));

【问题讨论】:

  • 你试过 position: absolute 吗?
  • 是的,我已经尝试过了,它在简单页面上工作,但在 wkhtmltopdf 页面上没有

标签: php html css pdf wkhtmltopdf


【解决方案1】:

添加页面时,您可以通过页面选项传入页脚。

$footer = $this->load->view('footer', $data, true);

$page_options = [
    'footer-html' => "".str_replace("\n", ' ', $footer).""
];

$pdf   = new Pdf($pdf_options);
$pdf->addPage($view, $page_options); // page invoice

您也可以将header-html 用于标题。这会将页脚应用到您使用该选项添加的每个页面。

【讨论】:

猜你喜欢
  • 2013-11-18
  • 2020-09-05
  • 2023-03-24
  • 1970-01-01
  • 2021-02-07
  • 2013-07-06
  • 2023-04-01
  • 2013-09-26
  • 2022-07-07
相关资源
最近更新 更多