how to use PHP to write the PDF?

2019-07-16 16:53发布

问题:

It doesn't display ite1 value in the pdf. Why? Could you please, correct my mistake?

<?php


set_include_path($_SERVER['DOCUMENT_ROOT'] .'/mpdf/'); 

require('mpdf.php');

$n = 0;
$mpdf=new mPDF();

require_once('../../includes/common.php');
 $result = mysql_query("SELECT * from sgc where year = '2010'") or die(mysql_error());
$row=mysql_fetch_array($result);
$nric=$row['nric'];
$row=mysql_fetch_array($result);
$meta_ite=$row['meta_ite'];

$mpdf->WriteHTML('<p>Hello World</p>');

$html1 = '<table>
          <tr>
        <td width="388">Module Description</td>
        <td width="111"><div align="center">Grade</div></td>
        <td width="92"><div align="center">Earned</div></td>
        <td width="96"><div align="center">Authority</div></td>
        <td width="74"><div align="center">Series</div></td>
          </tr>';
        $unser = $meta_ite;
      $unser = unserialize($unser);
      $count = count($unser);
      for($j=0;$j<$count;$j++)
      {
          $ite1 = $unser[$i][0];
                //print_r ($unser[$i][0]."--".$unser[$i][1]."--".$unser[$i][2]);

$html1 .= '<tr><td width="388">'.$nric.'</td>
<td width="111">'.$count.'</td>
<td width="92"><div align="center">'.$ite1.'</div></td>
<td width="96">ITE</td>
<td width="74">2010</td>
  </tr>';

      }
 $html1 .= '</table>';

 $mpdf->WriteHTML($html1);
 $mpdf->Output('filename.pdf','D');
?>

回答1:

first you include your mpdf file

require_once('./mpdf/mpdf.php');

also open debug functionality to see the error.

$mpdf->debug = true;

Note: ensure that you have complete permission (777 or 755) for the following folders on server:

/ttfontdata/
/tmp/
/graph_cache/



标签: mpdf