$ pdf-> SetFont将字体设置为整页

时间:2014-05-14 04:54:12

标签: php html tcpdf

$ 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();

1 个答案:

答案 0 :(得分:0)

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

$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';