3

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

4
  • Have you tried SetMargins? Commented Sep 9, 2018 at 6:34
  • @gonutz Yes..Did not work out Commented Sep 9, 2018 at 6:55
  • Can I ask where you entered the setMargins function? it is possible that from the position does not give you the desired result. maybe you could try with setLeftMargin inserting something like: "$ pdf-> SetLeftMargin(20); // 2cm". I did a test first and I had no problems. Let me know if this works. Commented Sep 9, 2018 at 8:05
  • Try this ... $this->Cell($w[$i],7,' '.$header[$i],1,0,'L',true); Commented Sep 17, 2018 at 21:45

3 Answers 3

4

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); 
Sign up to request clarification or add additional context in comments.

Comments

0

I have done it by adding more space in string. For example, '...... .. . . . . . .Stock Code' (replace '.' with space).

It is a hardcore way, but it works for me.

Comments

-1

$this -> Cell(80);

// Move to 8 cm to the right and the below cell follow on the same line

$this -> Cell($w[$i], 7, $header[$i], 1, 0, 'L', true);

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.