无法使用 MPDF 打印 PDF 文件


Failed to print PDF file with MPDF

我想将报告页导出为 PDF 文件,并且正在使用 MPDF。我正在逐步遵循其教程,但我得到 PDF 文件的空白页。在控制器中:

function download(){
    $this->load->library('m_pdf');
    $this->load->model('mod');
    $data['result'] = $this->mod->getReport();
    $html = $this->load->view('Laporan/index', $data);
    $this->m_pdf->pdf->WriteHTML($html);
    $this->m_pdf->pdf->Output('report.pdf', "D");    
}

怎么了?为什么要发送空白的 pdf 文件?

试试这个

function download(){
    $this->load->library('m_pdf');
    $this->load->model('mod');
    $data['result'] = $this->mod->getReport();
    $html = $this->load->view('Laporan/index', $data, true);
    $mpdf = $this->m_pdf->load(); # added 
    $mpdf->WriteHTML($html); # Changed
    $mpdf->Output('report.pdf', "D");    # Changed
}

检查您的库是否已加载

if(class_exists('m_pdf')) {
    echo "loded";
}
else{
    echo "Failed";
}