Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is there a left and top padding in a cell using TCPDF in php?

I am printing a cell using the TCPDF(http://www.tcdf.org/) class in php. The cell should be placed into the top left corner.

Everything works great, except that a left and top padding is added inside the cell.

Here is my code:

require_once('../config/lang/eng.php');
require_once('../tcpdf.php');

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

$pdf->SetMargins(0,0,0);
$pdf->SetAutoPageBreak(0,0);
$pdf->SetFont('dejavusans', '', 8.5, '', true);

$pdf->AddPage('L', array(50.8,88.9));
$pdf->SetDisplayMode(100,'default');

$pdf->SetXY(0, 0);
$pdf->Cell(0,2.98740833, "Your Name", '1', 2, 'L', false); //Name

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

Here's a screenshot of the PDF that is outputting with TCPDF:

Here's a screenshot of the PDF that is outputting with TCPDF:

Here's a screenshot of the same cell at 300% magnification:

Close-up of the padding in the cell

How can I remove the unwanted padding?

///EDIT///

I managed to remove the left padding by using the setCellPaddings() function:

$pdf->setCellPaddings(0,0,0,0);

I am however still getting padding above and below the text within the cell:

enter image description here

I can increase the size of the cell, but when I try to make the height of the cell smaller to try and close it in on the text, the cell won't get any smaller than the current size. How can I decrease the height of the cell or remove the unwanted top and bottom padding of the cell?

like image 578
zeckdude Avatar asked Jun 26 '11 10:06

zeckdude


2 Answers

If I'm not mistaken, that it is not padding, but space for letters which extend below the baseline (e.g. "g"), accents, subscripts and superscripts.

I tried your code with some accented letters in the text. This is the result: tcpdf test

Relevant:
- Baseline (typography)
- Subscript & Superscript

like image 66
Davorin Avatar answered Sep 20 '22 08:09

Davorin


On an additional note, you can decrease the height of the cell by passing TRUE for the ignoreMinHeight parameter in the Cell function.

like image 30
Romain Bessuges-Meusy Avatar answered Sep 17 '22 08:09

Romain Bessuges-Meusy