在tcpdf中使用两种不同类型的字体


make use of two different type of font in tcpdf

在下面的代码中,我使用两种字体fruit和fruit bold..所以当我使用的时候整个页面都是加粗的。但我想两者都用上。例如:hello应该用水果表示,world应该用粗体表示。我什么办法都试过了,都没用。

<?
require_once('../tcpdf.php');   //include tcpdf library
        $pdf = new TCPDF();
        $pdf->AddPage('P', 'A4');
        $fruit=$pdf->AddFont('fruit');
        $pdf->SetFont($fruit['family']);
        $fruit_bold=$pdf->AddFont('fruit_bold');
        $pdf->SetFont($fruit_bold['family']);
    $html='<html>
  <head>
  </head>
  <body>
      <table width="100%" border="0"  style="font-size:24px;" >
        <tr>
        <td>Hello World</td>
        </tr>
        </table>';
  $pdf->writeHTML($html, true, false, true, false, '');
  $pdf->Output();
?>

我终于找到解决办法了。你可以这样使用两种或更多的字体

<?
require_once('../tcpdf.php');       //include tcpdf library
    $pdf = new TCPDF();
    $pdf->AddPage('P', 'A4');
    $fruit=$pdf->AddFont('fruit');        //custom font
    $fruitb=$pdf->AddFont('fruitb');      //custom font
    $html='
    <style>
    span{
        color: navy;
        font-family: fruitb;
        font-size: 16pt;
    }
    p {
        color: red;
        font-family: fruit;
        font-size: 16pt;
    }
    </style>
    <span>My text in bold</span>
    <p>Normal text</p>';
    $pdf->writeHTML($html, true, false, true, false, '');
    $pdf->Output();
    ?>