TCPDF - PageNumber重复

时间:2017-02-11 15:52:33

标签: php pdf tcpdf

我在TCPDF中执行了自定义页眉和页脚功能,Header工作正常,但页脚有时会显示页眉中的PageNumber。我意识到如果我在AddPage()之前调用Footer(),则PageNumber在第一个PDF页面中显示重复,如果我之后调用它,则第二个PDF页面显示重复它。 为什么会出现这种情况?

// Include the main TCPDF library (search for installation path).
define('K_PATH_IMAGES', '');
require_once('TCPDF/tcpdf.php');
require 'crud/database.php';

class MyTCPDF extends TCPDF {

    var $htmlHeader;
    var $linestyle = array('color' => array(255, 0, 0));
    public function SetHtmlHeader($htmlHeader) {
        $this->htmlHeader = $htmlHeader;
    }

    public function Header() {
        $this->writeHTMLCell($w = 0,
            $h = 0,
            $x = '',
            $y = '',
            $this->htmlHeader,
            $border = 0, $ln = 1,
            $fill = 0,
            $reseth = true,
            $align = 'top',
            $autopadding = true);
        $this->Line(5, 55, 195, 55, $this->linestyle);

    }

    public function Footer() {
        $this->SetY(-17);
        $this->SetX(-10);
        // Set font
        $this->SetFont('helvetica', '', 12);
        // Page number
        $this->Cell(0, 10, $this->getAliasNumPage(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
    }

}


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

$pdf->SetTitle('Laudo pericial:');

// set default header data
$cabecalho = "
<style type=\"text/css\">
        .texto {
                font-family:  Zurich LtCn BT, sans-serif;
                margin-bottom: 3px;
                margin-top: 3px;
                direction: ltr;
                color: #000000;
                text-align: justify;
                font-style: italic;
                font-size: 8pt;
        }
</style>

<body lang=\"pt-br\" text=\"\"#000000\" link=\"#0000ff\" dir=\"ltr\">
<div>
    <p><font color=\"\"#808080\">

        </font>
    </p>
    <p align=left class=\"texto\" style=\"font-size: 9pt;\">
                Luiz  Carlos  Moreira
    </p>
    <p align=left class=\"texto\">
            Especialista Em Medicina Do Trabalho Anamt / Amb<br>
            Ergonomista Certificado Abergo <br>
            Profissional Certificado Pcmso-g (galvanoplastia) /fundacentro<br>
            Membro Do Icoh &ndash; International Commission On Occupational Health<br>
            Associado &agrave; Sociedade Paulista De Per&iacute;cias M&eacute;dicas<br>
            Associado &agrave; Sociedade Brasileira De Per&iacute;cias M&eacute;dicas <br>
            Especialista Em Per&iacute;cias M&eacute;dicas Pela Associa&ccedil;&atilde;o Brasileira De Medicina Legal E Per&iacute;cias M&eacute;dicas &ndash; Abmlpm / Amb<br>
            M&eacute;dico Perito Da Justi&ccedil;a Do Trabalho De Campinas
    </p>

</div>
</body>";

$pdf->SetMargins(PDF_MARGIN_LEFT+10, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHtmlHeader($cabecalho);

$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

$pdf->Footer();
$pdf->AddPage();  

$pdf->Output('test.pdf', 'I');

我的问题的例子:

enter image description here

1 个答案:

答案 0 :(得分:0)

感谢@Khem, 我删除了对Footer()函数的调用,它解决了问题。