Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FPDF table cell padding

Tags:

fpdf

I have created table using cells in FPDF..But Im not able to give padding for the cells and the text starts exactly near to the margin.How can we give a padding space at the beginning of the text.

I have attached the code here

    $w = array(90, 20, 20, 12, 20);
    for($i=0;$i<count($header);$i++)
    {
            $this->Cell($w[$i],7,$header[$i],1,0,'L',true);     
    }

The output is as below

enter image description here

BUt I want it to be disaplyed with left padding as below

enter image description here

like image 620
affaz Avatar asked Aug 03 '26 11:08

affaz


1 Answers

The FPDF Class has a protected property for cell margin:

protected $cMargin;            // cell margin

I'm not certain if the addition of this property post-dates the original post of this question, but it's available in Version: 1.83. However, there is no method to set this value, so it may be best to extend the class and add your own. For example:

class MyFPDF extends FPDF
{
    function SetCellMargin($margin) { $this->cMargin = $margin; }
}

Change the class name "MyFPDF" to whatever you wish. You'll need to construct the PDF using this class name instead of "FPDF" and set the value to what you wish:

$pdf = new MyFPDF();
$pdf->SetCellMargin(4);
like image 91
matteo Avatar answered Aug 06 '26 23:08

matteo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!