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

谁说我不能喝 提交于 2019-11-30 02:43:30

问题


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 same cell at 300% magnification:

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:

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:


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:

Relevant:
- Baseline (typography)
- Subscript & Superscript




回答2:


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



来源:https://stackoverflow.com/questions/6483326/why-is-there-a-left-and-top-padding-in-a-cell-using-tcpdf-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!