FPDF MultiCell() displays text across one or more lines inside a fixed width. When the text reaches the available width, FPDF automatically wraps the remaining text onto the next line.

This makes MultiCell useful when the length of the text is not known in advance. A normal Cell() does not automatically wrap long text.
$pdf->MultiCell(width,line_height,text,border,align,fill);
Show Table of Contents
$pdf->MultiCell(w,h,txt,border,align,fill);
'L', 'C', 'R' or 'J'.true to apply the current fill color.h parameter is the height of each text line. If the text wraps to three lines with h=10, the rendered MultiCell will normally consume about 30 units vertically.
The following example displays similar text first with Cell() and then with MultiCell().
<?php
require 'fpdf.php';
$pdf=new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->SetX(50);
$pdf->Cell(
60,
10,
'This is Cell - Welcome to plus2net.com',
1,
1,
'L',
false
);
$pdf->Ln(20);
$pdf->SetX(50);
$pdf->MultiCell(
60,
10,
'This is MultiCell - Welcome to plus2net.com',
'LRTB',
'L',
false
);
$pdf->Output('I','my_file.pdf');
View Difference between MultiCell() and Cell()
The second parameter supplied to MultiCell() controls the height of each line.
$pdf->MultiCell(
60,
10,
'Long text that may wrap to several lines',
1,
'L'
);
If the text occupies one line, the vertical space is approximately 10 units. If it wraps to two lines, the MultiCell consumes approximately 20 units. With three lines it consumes approximately 30 units.
Total vertical space = number of rendered lines x line height
This behavior is different from Cell(), where the text remains on a single line even when it is longer than the Cell width.
The border parameter can draw all sides or selected sides of the MultiCell.
1 - border on all sides.0 - no border.'L' - left border only.'RT' - right and top borders.'BTL' - bottom, top and left borders.'LRTB' - all four sides.$pdf->MultiCell(
100,
10,
'Text with selected borders',
'LRT',
'L'
);
View MultiCell Border Options
MultiCell supports the following common text alignment values:
'L' - left alignment.'C' - center alignment.'R' - right alignment.'J' - justified text.<?php
require 'fpdf.php';
$pdf=new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->SetX(50);
$pdf->MultiCell(100,10,'Alignment = L',1,'L',false);
$pdf->Ln(10);
$pdf->SetX(50);
$pdf->MultiCell(100,10,'Alignment = R',1,'R',false);
$pdf->Ln(10);
$pdf->SetX(50);
$pdf->MultiCell(100,10,'Alignment = C',1,'C',false);
$pdf->Ln(10);
$pdf->SetX(50);
$pdf->MultiCell(
100,
10,
'Longer text is useful when demonstrating justified alignment inside an FPDF MultiCell.',
1,
'J',
false
);
$pdf->Output('I','my_file.pdf');
View MultiCell Alignment Options
Use SetFillColor() to define the RGB background color and pass true as the final MultiCell parameter.
<?php
require 'fpdf.php';
$pdf=new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->SetX(50);
$pdf->MultiCell(
100,
10,
'Fill value is false',
1,
'C',
false
);
$pdf->Ln(10);
$pdf->SetFillColor(1,255,255);
$pdf->SetX(50);
$pdf->MultiCell(
100,
10,
'SetFillColor(1,255,255)',
1,
'C',
true
);
$pdf->Ln(10);
$pdf->SetFillColor(255,255,1);
$pdf->SetX(50);
$pdf->MultiCell(
100,
10,
'SetFillColor(255,255,1)',
1,
'C',
true
);
$pdf->Ln(10);
$pdf->SetFillColor(255,1,255);
$pdf->SetX(50);
$pdf->MultiCell(
100,
10,
'SetFillColor(255,1,255)',
1,
'C',
true
);
$pdf->Output('I','my_file.pdf');
View MultiCell Fill Colors
MultiCell changes the current PDF cursor position differently from Cell.
SetX(), SetXY() or margins when you need to position the next block manually.
The following example reads the current coordinates using GetX() and GetY().
<?php
require 'fpdf.php';
$pdf=new FPDF();
$pdf->SetLeftMargin(50);
$pdf->SetTopMargin(30);
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$line_height=15;
$width=100;
for($i=1;$i<=3;$i++){
$x=$pdf->GetX();
$y=$pdf->GetY();
$pdf->MultiCell(
$width,
$line_height,
'Before MultiCell: X='.round($x).', Y='.round($y),
'LRTB',
'L',
false
);
}
$x=$pdf->GetX();
$y=$pdf->GetY();
$pdf->MultiCell(
$width,
$line_height,
'X='.round($x).', Y='.round($y).
' - Extra text is added here so the content wraps onto another line and increases the final Y position.',
'LRTB',
'L',
false
);
$pdf->Output('I','my_file.pdf');
We use the Plus2net PHP round() tutorial here to display shorter coordinate values.
View MultiCell X and Y Position DemoFPDF does not automatically calculate the font size from the MultiCell height. However, for a controlled layout we can calculate a font size from the chosen line height.
$line_height=15;
$font_size=$line_height*0.75;
$pdf->SetFont(
'Arial',
'B',
$font_size
);
0.75 is not an FPDF requirement and may need adjustment for different fonts, widths and content.A complete demonstration:
<?php
require 'fpdf.php';
$pdf=new FPDF();
$pdf->SetLeftMargin(50);
$pdf->SetTopMargin(30);
$pdf->AddPage();
$width=100;
$line_height=35;
$font_size=0.75*$line_height;
$pdf->SetFont('Arial','B',$font_size);
$pdf->MultiCell(
$width,
$line_height,
'line height='.$line_height.', font size='.$font_size,
'LRTB',
'L',
false
);
$line_height=25;
$font_size=0.75*$line_height;
$pdf->SetFont('Arial','B',$font_size);
$pdf->MultiCell(
$width,
$line_height,
'line height='.$line_height.', font size='.$font_size,
'LRTB',
'L',
false
);
$line_height=10;
$font_size=0.75*$line_height;
$pdf->SetFont('Arial','B',$font_size);
$pdf->MultiCell(
$width,
$line_height,
'line height='.$line_height.', font size='.$font_size,
'LRTB',
'L',
false
);
$pdf->Output('I','my_file.pdf');
Demo: Font Size based on MultiCell Line Height
The existing Plus2net example also demonstrates a simple calculation based on text length, width and line height:
$cell_data="Welcome to plus2net, PHP section,
read more on how to generate PDF documents here";
$chars_no=strlen($cell_data);
$font_size=0.75*($width/$chars_no)*($line_height/5);
$pdf->SetFont('Arial','B',$font_size);
$pdf->MultiCell(
$width,
$line_height,
$cell_data,
'LRTB',
'L',
false
);
strlen().The text will wrap only when it requires more width than the MultiCell provides. Reduce the width or use a longer string to demonstrate wrapping.
This is normal MultiCell behavior. After MultiCell finishes, X returns to the current left margin. Use SetX() or SetXY() before drawing the next element if another horizontal position is required.
The height argument is the height of each line. When text wraps onto several lines, the total vertical space increases accordingly.
Call SetFillColor() and set the MultiCell fill argument to true.
Justification is most visible when the text wraps across multiple lines. A short single-line string does not demonstrate it well.
strlen() counts characters but does not measure their rendered width. Characters such as W and i occupy different amounts of space, so character-count formulas should be treated as approximations.
MultiCell() displays text inside a fixed width and automatically wraps long content onto additional lines.
Cell() is mainly used for single-line content, while MultiCell() can automatically wrap longer text over multiple lines.
No. The height parameter specifies the height of each rendered line. The total vertical space increases when the text wraps onto additional lines.
Use 1 for a border on all sides or use letters such as L, R, T and B to select individual sides.
Use L for left, C for center, R for right or J for justified alignment.
Set the color with SetFillColor() and pass true as the fill parameter of MultiCell().
Y moves down according to the number of rendered lines, and X returns to the current left margin after the MultiCell finishes.
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.