【问题标题】:Failed to print PDF file with MPDF使用 MPDF 打印 PDF 文件失败
【发布时间】:2016-01-19 19:58:45
【问题描述】:

我想将报告页面导出为 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文件?

【问题讨论】:

  • echo $html 并检查。你会得到答案
  • 它显示的不是空白页。但其所有内容@Abdulla
  • 可以将其作为其中的一部分发布
  • 是什么的一部分?我的查看页面/$html? @阿卜杜拉

标签: php codeigniter pdf mpdf


【解决方案1】:

试试这个

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";
}

【讨论】:

  • 谢谢@Abdulla 但它不起作用,出现错误。致命错误:调用未定义的方法 M_pdf::load()
  • 你确定库已经加载了吗??
  • @Diyah 浏览此tutorial
  • 如何检查我的库是否已加载?
  • 通过上面的链接。它们清楚地显示了如何添加以及在何处添加
猜你喜欢
  • 1970-01-01
  • 2012-05-27
  • 2021-03-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-06-28
  • 2016-03-04
  • 2018-11-27
相关资源
最近更新 更多