无法加载PDF文档?

时间:2017-01-13 08:31:29

标签: php html pdf mpdf

Record.php

<?php
  if(isset($_POST['btn'])){
    if(!isset($error)){

    //create html of the data
    ob_start();
?>
<?php 
    $body = ob_get_clean();
    $body = iconv("UTF-8","UTF-8//IGNORE",$body);
    include("mpdf/mpdf.php");
    $mpdf=new \mPDF('c','A4','','' , 0, 0, 0, 0, 0, 0); 
    //write html to PDF
    $mpdf->WriteHTML($body);
    $mpdf->SetDisplayMode('fullpage');
    $mpdf->list_indent_first_level = 0;
    $mpdf->WriteHTML(file_get_contents('Records.php'));
    $mpdf->Output();
   }
}
?> 

我正在尝试制作当前文件的pdf文件。它有一个表从数据库中获取数据。问题是,当我点击按钮时,它会将我重定向到pdf文件,但它给了我错误,错误是“无法加载PDF文档”。你可以看到下面的错误。我在做什么错??

enter image description here

1 个答案:

答案 0 :(得分:0)

简单易懂:

<?php
 include("mpdf/mpdf.php");
 echo '<table border="1">';
 echo '<tr><td>Put some content here!</td></tr>';
 echo '</table>';
 $html = ob_get_contents();
 $filename = 'filename.pdf';
 $mpdf = new mPDF('utf-8', 'A4-P');
 $mpdf->WriteHTML($html);
 $mpdf->Output($filename,'I');

不需要转换字符集,此库已在UTF-8中运行。