How to auto resize the cell in fpdf using php

后端 未结 2 1263
忘了有多久
忘了有多久 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: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.

提交回复
热议问题