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

时间:2014-05-13 08:03:44

标签: php html css tcpdf

在下面的代码我使用两个字体水果和水果粗体..所以当我使用这整个页面是粗体。但我想利用两者。前:你好,应该是水果,世界应该是大胆的.. 我尝试过所有事情没有成功。

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

?>

1 个答案:

答案 0 :(得分:4)

我终于找到了解决方案..你可以用这种方式使用两种或更多字体

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