3

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???

doydoy44
  • 5,720
  • 4
  • 29
  • 45
Jara Skuder
  • 91
  • 2
  • 16

2 Answers2

8

Do you want FPDF::GetStringWidth?

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

Mike S.
  • 1,995
  • 13
  • 25
1

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

pankaj
  • 1
  • 17
  • 36