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?
-
3class 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); } } – Bill Nov 02 '11 at 23:49
-
try the code above should eliminate the problem – Bill Nov 02 '11 at 23:49
-
1An alternative which doesn't involve editing the tcpdf class or extending it is presented in [this answer](https://stackoverflow.com/questions/2217132/changing-or-eliminating-header-footer-in-tcpdf) – Ian Gregory Jun 18 '12 at 21:12
6 Answers
This works for some versions:
// Call before the addPage() method
$pdf->SetPrintHeader(false);
$pdf->SetPrintFooter(false);
-
16This works fine but I would like to specify what these lines must be added before calling AddPage() method. – Dayron Gallardo Aug 05 '13 at 15:30
-
-
Not sure why the above answer was marked as correct, this is the correct answer. Thank you. – user1785684 Dec 04 '18 at 09:55
-
There is no configuration constant to tell that to TCPDF? Because this means you have to put these 2 lines for every TCPDF usage, which can be painful if you have several PDF exports – Xenos Mar 13 '19 at 10:32
-
2@Xenos You can always subclass TCPDF and override the `->AddPage()` calling those two lines, and then calling the parent. – Xavi Montero May 01 '19 at 16:10
-
@XaviMontero which means I'll have to change all TCPDF instantiation in favor of the subclas instance... It's a way to bypass this issue but this can only be done before using TCPDF, and no afterward (when poor legacy architecture wasn't already using a subclass nor a central factory)... – Xenos May 02 '19 at 07:32
-
@Xenos Well... if the code is "very legacy" and does a "new" all over there, I see one fast way to change this: Make your class to also be named TCPDF but locate it in another namespace such as `\MyApp\Pdf`. Then search for all the files containing `new TCPDF` or there any static usages `TCPDF::` and just at the beginning of the file place `use \MyApp\Pdf\TCPDF`. I'd would be great to use Dependency Injection if you could; but in the meantime you refactor, this does the trick. – Xavi Montero May 03 '19 at 09:15
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) );

- 12,636
- 12
- 67
- 104
-
2This actually answers the question. If you are, however, looking to completely disable the Header and Footer (like I was), then the answer from @András is what you want. – Ethan Hohensee Apr 18 '17 at 02:37
-
Not worked for me dear, still showing a horizonal row / line in header section of pdf. Thanks. – Kamlesh Aug 17 '23 at 11:33
-
https://stackoverflow.com/a/17172044/10329023 solution worked for me. Thanks – Kamlesh Aug 17 '23 at 11:34
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);
}
}
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)));

- 110
- 3
-
8This is not the answer. In common case if no data added into header and footer it's better to disable header and footer, that is pointed in other answers here. – Valera Leontyev Feb 27 '15 at 09:04
-
3A bit old, but still can't understand why this was chosen as the right answer – El Gucs Feb 17 '16 at 05:17
-
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.

- 53
- 2
- 9