How to wrap a text inside a Cell function in FPDF?

How to wrap a text inside a Cell function in FPDF?



sample output



This is my codes:


$pdf->SetFillColor(255,255,255);
$pdf -> SetTextColor(0,0,0);
$pdf -> SetFont ("Times","B","10");
$pdf -> Cell(60,7,"NAME AND ADDRESS OF SCHOOL",'L,T',0,'L','false');
$pdf -> Cell(32,7,"LEVEL",'L,T',0,'L','false');
$pdf -> Cell(28,7,"DATE FROM",'L,T',0,'L','false');
$pdf -> Cell(28,7,"DATE TO",'L,T',0,'L','false');
$pdf -> Cell(28,7,"DEGREE",'L,T',0,'L','false');
$pdf -> Cell(20,7,"AWARDS",'L,T,R',1,'L','false');


if (isset($_GET['id']))
$sql = "SELECT * FROM education_info WHERE applicant_code = " . $_GET['id'];
$result = mysqli_query($coonn, $sql);
$resultCheck = mysqli_num_rows($result);

if ($resultCheck > 0)
while ($row = mysqli_fetch_assoc($result)) # end of first php code


$pdf -> SetFont ("Times","","11");
$pdf -> Cell(60,5, $row['educ_name'],'T,L',0,'L','false');
$pdf -> Cell(32,5, "",'T,L',0,'L','false');
$pdf -> Cell(28,5, "",'T,L',0,'L','false');
$pdf -> Cell(28,5, "",'T,L',0,'L','false');
$pdf -> Cell(28,5, "",'T,L',0,'L','false');
$pdf -> Cell(20,5, "",'T,L,R',1,'L','false');

$pdf -> Cell(60,5, $row['educ_address'],'L,B',0,'L','false');
$pdf -> Cell(32,5, $row['educ_level'],'L,B',0,'L','false');
$pdf -> Cell(28,5, $row['educ_from'],'L,B',0,'L','false');
$pdf -> Cell(28,5, $row['educ_to'],'L,B',0,'L','false');
$pdf -> Cell(28,5, $row['educ_degree'],'L,B',0,'L','false');
$pdf -> Cell(20,5, $row['educ_award'],'L,R,B',1,'L','false');





I want to make the text go to the next line automatically if it have reached the end of the cell. I'm using the default format of Cell function in FPDF.


function Cell($w, $h=0, $txt='', $border=0, $ln=0, $align='', $fill=false, $link='')

// Output a cell
$k = $this->k;
if($this->y+$h>$this->PageBreakTrigger && !$this->InHeader && !$this->InFooter && $this->AcceptPageBreak())

// Automatic page break
$x = $this->x;
$ws = $this->ws;
if($ws>0)

$this->ws = 0;
$this->_out('0 Tw');

$this->AddPage($this->CurOrientation,$this->CurPageSize,$this->CurRotation);
$this->x = $x;
if($ws>0)

$this->ws = $ws;
$this->_out(sprintf('%.3F Tw',$ws*$k));


if($w==0)
$w = $this->w-$this->rMargin-$this->x;
$s = '';
if($fill



Is it possible to implement it just as the same with Cell function? Please help me. I got stuck here and this is the only thing I need to be done in order to finish my project. Thanks in advance!





use multiCell , for example : $pdf->MultiCell( 200, 40, $row['educ_address'], 1); or extend FPDF class with : fpdf.org/en/script/script49.php
– Fky
Aug 20 at 14:49


$pdf->MultiCell( 200, 40, $row['educ_address'], 1);




1 Answer
1



Your question addresses mostly not the limited Cell method but rather the Table creation.



If you want to draw an table where each row entity has the same height independent on the content size you should consider to implement one as proposed by @Fky or grasp an already available solution.. for example this one:



http://www.fpdf.org/en/script/script50.php





His question has nothing to do with cell or row height. It is about wrapping data within a cell when it exceeds the width of the cell.
– Dave
Aug 20 at 15:24





@Dave, trust me it surely does, its an known limitation in fpdf tool. It does not help him any further only to wrap data in one individual cell, you have to memorize all the the others cell height also and determine the highest one. Once you got it you can draw the next row based on the highest value. Without that height your table (and its obiviously an table) will looks something like collapsed wall.
– Christian Felix
Aug 20 at 18:37







By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

How can temperature be calculated given relative humidity and dew point?

I have a recursive function to validate tree graph and need a return condition

Oracle ADF: Log file reports ADFContext Leak