简体   繁体   中英

Cell width = text width FPDF

I have made a PDF exporter, which takes data from a model and export it in PDF by FPDF library.

$pdf = new FPDF();
$pdf->AddPage();

foreach ( $finalData AS $finalRow )
{
    foreach($finalRow as $one)
    {
        $pdf->SetFont("Arial", "", "8");
        $pdf->Cell(18, 5, $one, 1, 0, "C");
    }
    $pdf->Ln();
}

$pdf->Output();`

But I have too much info and the only way that my info would not go from Cell borders is to make that my cell width would be equal to text (because in some columns there are short text and in some are long). Does anyone have a clue how doing this???

Do you want FPDF::GetStringWidth ?

http://www.fpdf.org/en/doc/getstringwidth.htm

you can use this code to solve this problem.

$pdf->CellFit(35,19,"Message typed here for test only",1,0,'C',0,'',1,0);

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

sourse: http://www.fpdf.org/en/script/script62.php

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