17

I am using fpdf multicell to display an address. Each line in the address will be displayed in a new line like :

           102 South Avenue
           Suite 107
           Scottsdale AZ 85260
           111-000-1111

But the line height between each line is more than a new line. Any idea how to set the line height for MultiCell in FPDF?

janenz00
  • 3,315
  • 5
  • 28
  • 37

4 Answers4

31

Height is height of each text line in multicell, not height of whole multicell element.

What multiCell does is to spread the given text into multiple cells, this means that the second parameter defines the height of each line (individual cell) and not the height of all cells as a collective.

MultiCell(float w, float h, string txt [, mixed border [, string align [, boolean fill]]])

You can read the full documentation here.

Zuul
  • 16,217
  • 6
  • 61
  • 88
bboydev
  • 529
  • 5
  • 7
17

According to FPDF manual MultiCell is defined as

MultiCell(float w, float h, string txt [, mixed border [, string align [, boolean fill]]])

where h is "Height of cells".

That's a little confusing as h is the "line height" in normal language -- and the parameter you were looking for.

jsruok
  • 545
  • 7
  • 10
  • 3
    I swiched to TCPDF because of this issue, and several others. TCPDF is much more flexible compared to FPDF functions. – janenz00 Oct 01 '12 at 22:25
  • Awesome! TCPDF is a better choice. From the info it says: "// This class was originally derived in 2002 from the Public // Domain FPDF class by Olivier Plathey (http://www.fpdf.org), // but now is almost entirely rewritten and contains thousands of // new lines of code and hundreds new features." – El Gucs Feb 17 '16 at 03:06
-1
  1. you can use a library called advanced table witch makes this kind of thing a piece of cake.

  2. you can do what this guy did which includes adding spaces until each column has enough for a new row

My recommendation is the library although it costs around $8... its worth it for saving the time trust me.

-1
//reduce line height
$lineHeight=4;

$pdf->Cell(150, '102 South Avenue', 1, 0, 'L', true);
$pdf->Ln();
$pdf->Cell(150, 'Suite 107', 1, 0, 'L', true);
$pdf->Ln();
$pdf->Cell(150, 'Scottsdale AZ 85260', 1, 0, 'L', true);
$pdf->Ln();
$pdf->Cell(150, '111-000-1111', 1, 0, 'L', true);

//The Second column in the Cell adjusts line height size
MrMartiniMo
  • 149
  • 8