Codeigniter和TCPDF返回空白页


codeigniter and tcpdf returns blank page

我想有一个页面在codeIgniter导出为PDF。我按照以下说明安装了TCPDF库:TCPDF集成,现在我的控制器看起来像:

class Mycontroller extends CI_Controller {
    public function __construct(){
            parent::__construct();
            $this->load->library("Pdf");
    }
    //make pdf
    public function pdf(){
        $pdf = new Pdf('P', 'mm', 'A4', true, 'UTF-8', false);
        $pdf->SetCreator(PDF_CREATOR);
        // Add a page
        $pdf->AddPage();
        $html = "<h1>Test Page</h1>";
        $pdf->writeHTML($html, true, false, true, false, '');
        $pdf->Output('output.pdf', 'I');
    }
}

然后,我有一个链接在另一个页面:

<td><a href="<?php echo base_url(); ?>index.php/myController/pdf">Export As Pdf</a></td>

,当我点击它,我得到一个空白的pdf。该页的内容不在那里。

非常感谢任何帮助。谢谢你!

Try This

    $pdf = new Pdf('P', 'mm', 'A4', true, 'UTF-8', false);
    $pdf->SetTitle('Reciept Pdf');
    $pdf->SetHeaderMargin(30);
    $pdf->SetTopMargin(20);
    $pdf->setFooterMargin(20);
    $pdf->SetAutoPageBreak(true);
    $pdf->SetAuthor('Author');
    $pdf->SetDisplayMode('real', 'default');
    $pdf->Write(5, 'CodeIgniter TCPDF Integration');
    $pdf->AddPage();
    $pdf->writeHTML($html, true, false, true, false, '');
    $pdf->Output('reciept.pdf', 'I');