如何在页面底部添加页脚wkhtmltopdf

时间:2021-01-02 19:39:15

I am using wkhtmltopdf to genereate reports now i have encounterd with a situation where i have to show footer at the bottom of the page i have tried to solve this with css it works on simple page but not on my wkhtmltopdf generated page here is my HTML code

我正在使用wkhtmltopdf生成报告现在我遇到的情况我必须在页面底部显示页脚我试图用css解决这个问题它在简单的页面上工作但不在我的wkhtmltopdf生成页面这里是我的HTML码

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

And my css is this

而我的CSS就是这个

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

I have also tried this code given on wkhtmltopdf page

我也尝试过在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>

Note I am not using cmd command I am using CodeIgniter. Is their any option like

注意我没有使用cmd命令我正在使用CodeIgniter。他们的任何选择都是

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

1 个解决方案

#1


3  

When adding your page you can pass in a footer through the page options.

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

$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

You can also use header-html as well for headers. This will apply the footer to each page you add with that option.

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

#1


3  

When adding your page you can pass in a footer through the page options.

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

$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

You can also use header-html as well for headers. This will apply the footer to each page you add with that option.

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