【问题标题】:The data that comes as HTML echos right on modal window but does not show in PDF以 HTML 形式出现的数据在模态窗口中回显,但未在 PDF 中显示
【发布时间】:2016-12-03 18:31:54
【问题描述】:

我正在开发 codeigniter。我正在将数据从视图发送到接收数据的文件,当我回显它时,它会显示在模态窗口上,但是一旦我写 $mpdf->Output();,数据就不会显示,屏幕显示为:

我发送的 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();

【问题讨论】:

    标签: php html css codeigniter mpdf


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

      使用 ob_end_clean();在 header('Content-type: application/pdf');

      【讨论】:

        猜你喜欢
        • 2011-02-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-12-05
        相关资源
        最近更新 更多