11

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?

1
  • In my case I just wanted to remove the left and right padding, so my code is $pdf->setCellPaddings(0,'','',0);. Thanks to your question and answer I could easily figure this out... Commented Jun 20, 2017 at 2:39

2 Answers 2

17

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

1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.