简体   繁体   中英

How to auto resize the cell in fpdf using php

I need to auto adjust the cell size depends upon the text . I have the following code .

$pdf->Cell(50,10,$name,1,0,'L',0);

If the $name exceed 10 character means the $name wrap into the next cell. How to fix?

I refer to: GetStringWidth and SetFont . As pointed out there, to use this method, a font must be selected. So I assume, you already have something like:

.
.
$pdf->AddPage();

$fontFamily = 'Courier'; // 'Courier', 'Helvetica', 'Arial', 'Times', 'Symbol', 'ZapfDingbats'
$fontStyle = 'B'; // 'B', 'I', 'U', 'BI', 'BU', 'IU', 'BIU'
$fontSize = 12.0; // float, in point

$pdf->SetFont($fontFamily, $fontStyle, $fontSize);


To adjust the cell width to the length of the text, let its value take the calculated length of the text:

$width = $pdf->GetStringWidth($name);
$height = 10.0;
$border = 1;
$ln = 0;
$align = 'L';
$fill = FALSE;

$pdf->Cell($width, $height, $name, $border, $ln, $align, $fill);



Havn't tested it, just read the manual. Hope it works.

you can use this code to solve this problem... here the concept is only if string size greater than your cell width then font size will reduce.

$pdf->CellFit($table_head2[7],$table_height,$item['remark'],1,0,'C',0,'',1,0);

check this URL

how to auto adjust cell width in fpdf using php and mysql

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM