【问题标题】:$pdf->SetFont sets the font to whole page$pdf->SetFont 将字体设置为整页
【发布时间】:2014-05-14 04:54:12
【问题描述】:

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

【问题讨论】:

标签: php html tcpdf


【解决方案1】:

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

$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 的情况下,您可以将内联样式写入 span 并应用它。 // 试试这个看看有没有效果

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

【讨论】:

  • 即使在跨度标签内使用 $pdf->setFont 后,整个文档也反映了相同的字体..我希望字体只反映在跨度标签中
  • 您将通过参考这 2 个链接来回答您的问题。 tcpdf.org/examples/example_006.phps tcpdf.org/examples/example_006.pdf //这是php文件(example_006.phps)的pdf生成结果别忘了可以添加内联样式。
猜你喜欢
  • 2023-03-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-14
  • 2022-11-19
  • 2014-02-09
相关资源
最近更新 更多