php - 以 HTML 形式出现的数据直接在模式窗口中回显,但不显示在 PDF 中

标签 php html css codeigniter mpdf

我正在研究 codeigniter。我正在将数据从一个 View 发送到一个获取数据的文件,当我回显它时,它会立即显示在模态窗口中,但是一旦我编写 $mpdf->Output(); 数据就会显示出来不显示,屏幕显示为:
The error output on modal window

我发送的 html 是:

    $html='';

    $html .='
                <table width="100%" class="pat-demo" id="pqrs_csv_list">
                    <thead>
                        <tr>
                            <th  class="cols">Measure ID</th>
                            <th  class="cols">Measure Name</th>
                            <th  class="cols">Met</th>
                            <th  class="cols">Not eligible</th>
                            <th  class="cols">Not met</th>
                            <th  class="cols">Exclusion</th>
                        </tr>

                    </thead>
                    <tbody>';

    foreach ($arr as $aRow)
    {
        if($counter==2) { $bgcolor =""; $counter=1;} else { $bgcolor = "#FFF9F9"; $counter++; }



        $html .='<tr bgcolor="'.$bgcolor.'">
                        <td  class="cols" width="8%">'.$aRow['measureId'].'</td>
                        <td  class="cols" width="55%%">'.$aRow['measureName'].'</td>
                        <td  class="cols" width="8%">'.$this->percentage($aRow[1], $total_visits)."%".'</td>
                        <td  class="cols" width="8%">'.$this->percentage($aRow[2], $total_visits)."%".'</td>
                        <td  class="cols" width="8%">'.$this->percentage($aRow[3], $total_visits)."%".'</td>
                        <td  class="cols" width="8%">'.$this->percentage($aRow[4], $total_visits)."%".'</td>
                    </tr>';
    }

$html .='</tbody>
            </table>';

然后采用此 HTML 的文件以及我尝试在 pdf 查看器中显示它的位置具有代码:

    $mpdf = new mPDF('utf-8', 'A4-L', 0, '', 10, 10, 32, 25, 5, 2,2,'P');       
$mpdf->SetHTMLHeader('<div style="text-align: center; font-weight: bold;">'.$header.'</div>');
$mpdf->SetHTMLFooter($footer);

$mpdf->defaultheaderfontsize=10;
$mpdf->defaultheaderfontstyle='B';
$mpdf->defaultheaderline=0;
$mpdf->defaultfooterfontsize=10;
$mpdf->defaultfooterfontstyle='BI';
$mpdf->defaultfooterline=0;
header('Content-type: application/pdf');
$stylesheet = file_get_contents('admin_includes/css/print_pdf.css');
$mpdf->WriteHTML($stylesheet,1);
//echo $html;/// here it echos right but not goes to pdf
$mpdf->WriteHTML($html);
$mpdf->Output();

最佳答案

可能需要添加其他 header 。也许尝试以下任何组合:

header('Content-Type: application/octet-stream');
header('Content-Transfer-Encoding: binary');
header('Content-disposition: attachment'); 

关于php - 以 HTML 形式出现的数据直接在模式窗口中回显,但不显示在 PDF 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40951145/

相关文章:

php - 按是或否排序

php - 发送邮件时缺少 <img> 的 src 属性

javascript - 如何改进此电子邮件地址验证方法?

php - PHP表单数据到多个MySQL条目

php - 在 Windows Server 上将 Word Doc 文件转换为 PDF

html - 不同高度的网格系统 css

javascript - 显示 PDF 但不下载

jquery - Firefox:点击 CSS 伪元素不会触发点击事件

css - 页脚栏上的文字

html - 如何让语义 UI 段正确适合页面宽度