0

我下面的codeigniter代码我正在处理pdf文件,当我执行它时,你好世界只显示而不是表格请帮助我解决问题。我把控制器放在下面。我从这个网站下载 http://www。 christophermonnat.com/2008/08/generating-pdf-files-using-codeigniter/

控制器:

<?php

class Tutorial extends controller
{

    function Tutorial()
    {
        parent::Controller();

        $this->load->helper('url');
    }


    function index() 
    {   
        $this->hello_world();
    }


    function hello_world()
    {
        $this->load->library('cezpdf');

        $this->cezpdf->ezText('Hello World', 12, array('justification' => 'center'));
        $this->cezpdf->ezSetDy(-10);

        $content = 'The quick, brown fox jumps over a lazy dog. DJs flock by when MTV ax quiz prog.
                    Junk MTV quiz graced by fox whelps. Bawds jog, flick quartz, vex nymphs.';

        $this->cezpdf->ezText($content, 10);

        $this->cezpdf->ezStream();
    }


    function tables()
    {
        $this->load->library('cezpdf');

        $db_data[] = array('name' => 'Jon Doe', 'phone' => '111-222-3333', 'email' => 'jdoe@someplace.com');
        $db_data[] = array('name' => 'Jane Doe', 'phone' => '222-333-4444', 'email' => 'jane.doe@something.com');
        $db_data[] = array('name' => 'Jon Smith', 'phone' => '333-444-5555', 'email' => 'jsmith@someplacepsecial.com');

        $col_names = array(
            'name' => 'Name',
            'phone' => 'Phone Number',
            'email' => 'E-mail Address'
        );

        $this->cezpdf->ezTable($table_data, $col_names, 'Contact List', array('width'=>550));
        $this->cezpdf->ezStream();
    }


    function headers()
    {
        $this->load->library('cezpdf');
        $this->load->helper('pdf');

        prep_pdf(); // creates the footer for the document we are creating.

        $db_data[] = array('name' => 'Jon Doe', 'phone' => '111-222-3333', 'email' => 'jdoe@someplace.com');
        $db_data[] = array('name' => 'Jane Doe', 'phone' => '222-333-4444', 'email' => 'jane.doe@something.com');
        $db_data[] = array('name' => 'Jon Smith', 'phone' => '333-444-5555', 'email' => 'jsmith@someplacepsecial.com');

        $col_names = array(
            'name' => 'Name',
            'phone' => 'Phone Number',
            'email' => 'E-mail Address'
        );

        $this->cezpdf->ezTable($db_data, $col_names, 'Contact List', array('width'=>550));
        $this->cezpdf->ezStream();
    }

}

?>
4

2 回答 2

0

试试 mPdf。将css样式的html直接转成pdf。在 CI 上,您可以将参数化视图加载到 mPdf 并生成文档。如果您不进行工作项目,则可以这样做。

于 2013-11-12T16:36:19.943 回答
-1

您可以使用 mPDF 在 Codeigniter 中生成 PDF。

您可以创建一个控制器类,然后在其中创建函数。然后做一些如下代码 -

public function mypdf() { 
    $this->load->library('pdf'); 
    $pdf = $this->pdf->load(); 
    $html=$this->load->view('welcome_message',null,true); 
    $pdf->WriteHTML($html); 
    // write the HTML into the PDF 
    $output = 'itemreport' . date('Y_m_d_H_i_s') . '_.pdf'; 
    $pdf->Output("$output", 'I'); 
}

有关更多详细信息,您可以将 mPDF 用于 codeigniter。教程在这里

或者

您可以尝试将 DOMPDF 用于 codeigniter。教程在这里

于 2016-11-08T04:17:16.567 回答