custom PHP tcpdf footer with top and bottom border

后端 未结 2 1452
情歌与酒
情歌与酒 2021-01-28 10:05

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 to

相关标签:
2条回答
  • 2021-01-28 10:10

    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.

    0 讨论(0)
  • 2021-01-28 10:10

    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);
    
    0 讨论(0)
提交回复
热议问题