我的问题是我在单元格中有一个中心文本,我想用粗体字表示“客户:”,其余的用常规字体表示,例如居中,我不能先打印“客户:”,然后再打印名称,由于居中,均不能使用“写入”功能,请提供帮助。
$pdf->SetTextColor(102, 106, 117);
$pdf->SetFont('Arial', 'B', 15);
$pdf->Cell(626,25,"Client: ".$name,0,0,'C',0);
答案 0 :(得分:1)
我们必须计算居中文本的位置,如下所示:
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示例-屏幕截图的一部分: