Zbyněk Dufka
Zbyněk Dufka

Reputation: 37

header and footer line in FPDI/TCPDF

I'm stamping my PDF documents with FPDI and TCPDF functions, and I'm trying to figure it out, how can I add a line below the text in Header, and upon the text in footer. Here is my code:

<?php

require_once('lib/tcpdf/tcpdf.php');
require_once('fpdi.php');


$fullPathToFile = "TestClanek6.pdf";  

class PDF extends FPDI {

    var $_tplIdx;

    function Header() {

        global $fullPathToFile;  //global 
        if(is_null($this->_tplIdx)) {
            // number of pages
            $this->numPages = $this->setSourceFile($fullPathToFile);
            $this->_tplIdx = $this->importPage(1);
        } 
        if($this->page > 0) {
            //$this->SetPrintHeader(true);
            $this->SetFont('times', 'I', 11); 
            $this->SetTextColor(0);
            $this->Write(15, "Vol. 1, No. 15, Year: 2015, duff");
            $this->Image('logo.png', 100, 2, 75,7);            
        } //end of IF
        $this->useTemplate($this->_tplIdx, 0, 0,200);
    }           //end of HEADER

    function Footer() {
        if($this->page > 0) {
            $this->SetY(-20);
            $this->SetFont('times', 'I', 11); 
            $this->SetTextColor(0,0,0);
            $this->Write(0, "Page", '', 0, 'C');
        }  //end of if
    } // end of footer
}        //end of CLASS

// new PDF file
$pdf = new PDF();
$pdf->addPage(); 
if($pdf->numPages>0) {
    for($i=1;$i<=$pdf->numPages;$i++) {
        $pdf->endPage();
        $pdf->_tplIdx = $pdf->importPage($i);
        $pdf->AddPage();
        //$pdf->SetPrintHeader(false);
        //$pdf->SetPrintFooter(false); 
    }
}
$file_time = time();

$pdf->Output("$file_time.pdf", "F");//, "I"); 
echo "Link: '<a href=$file_time.pdf>Stamped article</a>'"; 
?>

I've tried a lot of things like setPrintHeader(), etc. but nothing what I've found works for me. Could i please somebody to help?

Thank you.

duff

Upvotes: 0

Views: 10313

Answers (2)

ungalcrys
ungalcrys

Reputation: 5620

Better would be to leave the two methods (Header and Footer) empty. this way you would overwrite the drawing from super-class.

like this:

class EmptyFPDI extends FPDI
{
    public function Header()
    {
    }

    public function Footer()
    {
    }
}

Upvotes: 2

Muhammad Abdul-Rahim
Muhammad Abdul-Rahim

Reputation: 2030

You can use the Line method to draw a line in FPDF. If you want a straight horizontal line, just make sure the ordinates (y values) for the start and end of the line are the same. Something like this for example:

$pdf->Ln(15,$pdf->y,200,$pdf->y);

You would modify the values to suit your needs and insert it in the overridden methods for Header and Footer as appropriate for your application.

Upvotes: 3

Related Questions