How to auto resize the cell in fpdf using php

后端 未结 2 1265
忘了有多久
忘了有多久 2021-01-28 16:28

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 $

相关标签:
2条回答
  • 2021-01-28 16:41

    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

    0 讨论(0)
  • 2021-01-28 16:48

    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.

    0 讨论(0)
提交回复
热议问题