FPDF - PHP - 中心单元格的不同样式
FPDF - PHP - Different styles on center cell
我的问题是我的单元格中有一个居中文本,我希望单词 "Client:" 以粗体显示,其余部分以常规显示,例如居中 我无法先打印 "client:" ,然后再打印打印名称,既不使用 "write" 功能,因为居中,请帮助。
$pdf->SetTextColor(102, 106, 117);
$pdf->SetFont('Arial', 'B', 15);
$pdf->Cell(626,25,"Client: ".$name,0,0,'C',0);
我们必须计算居中文本的位置,如下所示:
require("fpdf.php");
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetTextColor(102, 106, 117);
$fullCellWidth = $pdf->GetPageWidth();
$pdf->SetFont("Arial", "", 15);
$regularCell = "some name";
$regularWidth = $pdf->GetStringWidth($regularCell);
$pdf->SetFont("Arial", "B", 15);
$boldCell = "Client: ";
$boldWidth = $pdf->GetStringWidth($boldCell);
$centerIndentX = ($fullCellWidth - $boldWidth - $regularWidth) / 2;
$pdf->SetX($centerIndentX);
$pdf->Cell($boldWidth, 25, $boldCell, 0, 0, "L");
$pdf->SetX($centerIndentX + $boldWidth);
$pdf->SetFont("Arial", "", 15);
$pdf->Cell($regularWidth, 25, $regularCell, 0, 0, "L");
$pdf->Output();
输出PDF示例-部分截图:
我的问题是我的单元格中有一个居中文本,我希望单词 "Client:" 以粗体显示,其余部分以常规显示,例如居中 我无法先打印 "client:" ,然后再打印打印名称,既不使用 "write" 功能,因为居中,请帮助。
$pdf->SetTextColor(102, 106, 117);
$pdf->SetFont('Arial', 'B', 15);
$pdf->Cell(626,25,"Client: ".$name,0,0,'C',0);
我们必须计算居中文本的位置,如下所示:
require("fpdf.php");
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetTextColor(102, 106, 117);
$fullCellWidth = $pdf->GetPageWidth();
$pdf->SetFont("Arial", "", 15);
$regularCell = "some name";
$regularWidth = $pdf->GetStringWidth($regularCell);
$pdf->SetFont("Arial", "B", 15);
$boldCell = "Client: ";
$boldWidth = $pdf->GetStringWidth($boldCell);
$centerIndentX = ($fullCellWidth - $boldWidth - $regularWidth) / 2;
$pdf->SetX($centerIndentX);
$pdf->Cell($boldWidth, 25, $boldCell, 0, 0, "L");
$pdf->SetX($centerIndentX + $boldWidth);
$pdf->SetFont("Arial", "", 15);
$pdf->Cell($regularWidth, 25, $regularCell, 0, 0, "L");
$pdf->Output();
输出PDF示例-部分截图: