42

Right now when I use a cell with text, it all stays on one line. I know I could use the write function, but I want to be able to specify the height and width.

This is what I have now, but as I said the text does not wrap to stay in the dimensions:

$pdf->Cell( 200, 40, $reportSubtitle, 1, 1 );
Carson
  • 4,541
  • 9
  • 39
  • 45

1 Answers1

80

Text Wrap:

The MultiCell is used for print text with multiple lines. It has the same atributes of Cell except for ln and link.

$pdf->MultiCell( 200, 40, $reportSubtitle, 1);

Line Height:

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 (collectively).

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

You can read the full documentation here.

Community
  • 1
  • 1
Ed.
  • 1,934
  • 15
  • 13
  • 5
    @PHPDeveloper & others see this: [line break problem with MultiCell in FPDF](http://stackoverflow.com/q/1419719/1544337) - this explains how to put cells next to a MultiCell. –  Jun 22 '13 at 12:50
  • 2
    This page shows a good example of how to use it in a table: http://www.fpdf.org/en/script/script3.php – Reece Sep 22 '16 at 17:25
  • MultiCell is useless, if you want a few cells - one next to each other - try this: https://stackoverflow.com/a/30359325/436443 – Jeffz Dec 13 '17 at 18:16
  • What about the `ln` parameter? Should it be explicitly given after MultiCell? – Paulo Marques Oct 20 '20 at 18:06