Bill
Bill

Reputation: 19268

PHP TCPDF remove header's bottom border

I am trying to create a header in TCPDF, however it always have a border underneath of it. Is there a way I can remove the bottom border?

Upvotes: 37

Views: 60105

Answers (6)

Nicolò Rebaioli
Nicolò Rebaioli

Reputation: 63

If the other solutions posted in this thread does not work, I solved in this way:

TL;DR
In Footer() function in Tcpdf class (tcpdf.php):
Replace this lines:

$this->Cell(0, 0, $pagenumtxt, 'T', 0, 'L'); // line 3527 in version 6.3.1
$this->Cell(0, 0, $this->getAliasRightShift().$pagenumtxt, 'T', 0, 'R'); // line 3530 in version 6.3.1

With this lines

$this->Cell(0, 0, $pagenumtxt, 0, 0, 'L');
$this->Cell(0, 0, $this->getAliasRightShift().$pagenumtxt, 0, 0, 'R');

Alternative way 1
Comment this lines in Footer() function in Tcpdf class (tcpdf.php):
In my file (version 6.3.1) they were placed at line 3524

//Print page number
if ($this->getRTL()) {
    $this->SetX($this->original_rMargin);
    $this->Cell(0, 0, $pagenumtxt, 'T', 0, 'L');
} else {
    $this->SetX($this->original_lMargin);
    $this->Cell(0, 0, $this->getAliasRightShift().$pagenumtxt, 'T', 0, 'R');
}

This will disable the render of the page number in the footer but at least it removes the unwanted line.

Alternative way 2
If these methods does not work, search in the tcpdf.php file for this string:

$this->SetLineStyle(array

You should find 3 occurrences, replace the 'color' property of the array with the value [0,0,0] (or the rgb color of your background), this should cause the line to turn white (or the color you set). I used this method to troubleshoot where the problem was by putting custom weird color and seeing which one was being rendered.

Explanation
The line is rendered because in the lines

$this->Cell(0, 0, $pagenumtxt, 'T', 0, 'L');
$this->Cell(0, 0, $this->getAliasRightShift().$pagenumtxt, 'T', 0, 'R');

The border property is set to 'T' (top border). You can disable the border by set the border property to 0 (see docs here, $border param). If that doesn't work you can entirely disable the render of the page number (and thus the border), or you can set the border to a custom color that matches you actual background.

Upvotes: 0

András
András

Reputation: 3475

This works for some versions:

// Call before the addPage() method
$pdf->SetPrintHeader(false);
$pdf->SetPrintFooter(false);

Upvotes: 137

Bill
Bill

Reputation: 19268

Problem solved by extends the TCPDF class and modify the header and footer.

class MYPDF extends TCPDF { 

    public function Header() 
    { 
        $image_file = K_PATH_IMAGES.'pdf-header.jpg'; 
        $this->Image($image_file, 160, 10, 40, '', 'JPG', '', 'T', false, 20, '', false, false, 0, false, false, false); 
        $this->SetFont('helvetica', 'B', 10); 
    } 

    public function Footer() 
    { 
        $this->SetY(-15); 
        $this->SetFont('helvetica', 'I', 8); 

    }
}

Upvotes: 4

James
James

Reputation: 12796

If you don't want to subclass or change the tcpdf source just call the setHeaderData method and specify white line color.

$pdf->setHeaderData('',0,'','',array(0,0,0), array(255,255,255) );  

Upvotes: 38

Rkk
Rkk

Reputation: 1

Comment this line in Header() function of tcpdf Class :

$this->Cell(($this->w - $this->original_lMargin - $this->original_rMargin), 0, '', 'T', 0, 'C');

Upvotes: -1

Patrik Ján
Patrik Ján

Reputation: 110

tcpdf.php:

// print an ending header line
$this->SetLineStyle(array('width' => 0.25 / $this->k, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(255, 255, 255)));

Upvotes: 3

Related Questions