custom PHP tcpdf footer with top and bottom border

浪尽此生 提交于 2019-12-02 21:53:02

问题


First time use TCPDF, great library.

I try to create a custom footer, however i want to create a custom footer that include the page number and date inside a div with top and bottom border! So any help?

Many Thanks


回答1:


Karel is right on this.

you could however ignore the Footer() function if it's getting you in trouble with the dynamic of it. seems to me that you would like to have a div in your footer.

to do this you have to get rid of the default footer first:

$this->setPrintFooter(false);

and then create your own footer function.

public function _footer($input) {
    $html = $input;

    $this->setY(-15); // so the footer is an actual footer.

    $this->writeHTMLCell(
        $width = 0, // width of the cell, not the input
        $height = 0, // height of the cell..
        $x,
        $y,
        $html = '', // your input.
        $border = 0,
        $ln = 0,
        $fill = false,
        $reseth = true,
        $align = '',
        $autopadding = true 
    );
}

the values of the above function are the defaults. so you may want to edit them.

with a call like this:

$div = '<div id="footer">wow this is a nice footer</div>'>
$pdf->_footer($div);

you create your HTML cell with the $div input.

to get the page numbers and stuff like that just checkout the TCPDF documentation page: http://www.tcpdf.org/doc/code/classTCPDF.html

hope this helps a little bit to understand it. this is just an example from scratch. edit it as you like and try out some stuff to get your PDF document going.




回答2:


You can extend the TCPDF class and add your custom Footer function. Here's an example that I've used, see if it fits and modify to your own needs. It doesn't use a <div> to render the footer, that wasn't possible at the time I wrote this (might be now though, TCPDF is evolving rapidly).

class MyPDF extends TCPDF {
    public function Footer() {
        $this->SetY(-15);
        $this->SetFont('helvetica', 'I', 8);
        $this->Cell(0, 10,
                    'Page ' . $this->getAliasNumPage() . ' of total ' .
                    $this->getAliasNbPages(), 0, false, 'C', 0, '',
                    0, false, 'T', 'M');
    }
    public function Header() {
        // add custom header stuff here
    }
}

$pdf = new MyPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT,
                 true, 'UTF-8', false);


来源:https://stackoverflow.com/questions/28275193/custom-php-tcpdf-footer-with-top-and-bottom-border

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!