$pdf->SetFont设置整个页面的字体


$pdf->SetFont sets the font to whole page

$pdf->SetFont将字体设置为整个页面,但我希望这种字体仅受span标签的影响。

require_once('../tcpdf.php');       
$pdf = new TCPDF();
$pdf->AddPage('P', 'A4');
$fruit=$pdf->AddFont('fruit');
$html='<span '.$pdf->SetFont($fruit['family']).'>my text in bold</span>This isnormal';
$pdf->writeHTML($html, true, false, true, false, '');
$pdf->Output();

您必须明确设置每种情况的字体。例如

$pdf->SetFont('times', 'B', 16);
// now time s font will applied for the following cell
$pdf->MultiCell(0, 0, 'Table Of Content', 0, 'C', 0, 1, '', '', true, 0);
$pdf->Ln();
$pdf->SetFont('helvetica', '', 10);
// This will override the time s font applied before and apply helvetica as the new font

在你的情况下,你正在传递一个html,你可以写内联样式的跨度,并得到它的应用。//请尝试一下,看看是否有效果

$html='<span style="font-weight:bold" '.$pdf->SetFont($fruit['family']).'>my text in bold</span>This isnormal';