FPDF - 如何使getstringwidth全局?

时间:2017-07-05 11:37:07

标签: php html mysql width fpdf

我想在getstringwidth使用while时仅在下一行设置宽度时调用while

我的表格标题:

while ($row2x = $stmt2x->fetch(PDO::FETCH_ASSOC)){
    $string = $row2x['nama_kriteria'];
    $cellwidth = $pdf->GetStringWidth($string);
    $pdf->Cell($cellwidth + 2,7,$row2x['nama_kriteria'],1,0,'L');
}

如何在下一个表格行中使用表格标题宽度?

我的表格行:

while ($rowrx = $stmtrx->fetch(PDO::FETCH_ASSOC)){
        $pdf->Cell(/*$cellwidth + 2*/,7,$rowrx['nilai_rangking'],1,0,'L');
    }

现在,我的表看起来像: this

任何想法如何让它好看?

1 个答案:

答案 0 :(得分:1)

尝试将宽度存储在数组中。

AuthenticationContext authenticationContext = new AuthenticationContext(UserModeConstants.AuthString, false);
AuthenticationResult userAuthnResult = await authenticationContext.AcquireTokenAsync(GlobalConstants.ResourceUrl,
      UserModeConstants.ClientId, redirectUri, new PlatformParameters(PromptBehavior.RefreshSession));
TokenForUser = userAuthnResult.AccessToken;
Console.WriteLine("\n Welcome " + userAuthnResult.UserInfo.GivenName + " " +
                              userAuthnResult.UserInfo.FamilyName);

你需要填充从$width = array(); while ($row2x = $stmt2x->fetch(PDO::FETCH_ASSOC)){ $string = $row2x['nama_kriteria']; $cellwidth = $pdf->GetStringWidth($string); $pdf->Cell($cellwidth + 2,7,$row2x['nama_kriteria'],1,0,'L'); $width[] = $cellwidth + 2; } $i = 0; while ($rowrx = $stmtrx->fetch(PDO::FETCH_ASSOC)) { $pdf->Cell($width[$i],7,$rowrx['nilai_rangking'],1,0,'L'); $i++; } 获得的宽度数组,然后你只需使用宽度变量宽度值