codeigniter将html页面转换为pdf并使用Html2pdf发送邮件

时间:2017-06-15 09:18:02

标签: php codeigniter email codeigniter-3

我在doceigniter中遇到html2pdf库的一个问题。我正在尝试使用Html2pdf库将视图页面作为pdf发送到邮件中,但我无法在codeigniter中实现此库

这是我的控制器代码

$this->load->library('Html2pdf');

    //Set folder to save PDF to
    $this->Html2pdf->folder('./assets/');

    //Set the filename to save/download as
    $this->Html2pdf->filename('test.pdf');

    //Set the paper defaults
    $this->Html2pdf->paper('a4', 'portrait');

    $data = array(
        'title' => 'PDF Created',
        'message' => 'Hello World!'
    );

    //Load html view
    $this->Html2pdf->html($this->load->view('pdf', $data, true));

    if($this->Html2pdf->create('save')) {
        //PDF was successfully saved or downloaded
        // echo 'PDF saved';
    }

当我运行此代码时,我收到此错误

  

遇到PHP错误   严重性:注意   消息:未定义的属性:示例:: $ Html2pdf   文件名:controllers / Example.php   行号:15

     

致命错误:调用非对象

上的成员函数文件夹()

请帮我实现这个库 谢谢大家

1 个答案:

答案 0 :(得分:0)

Please check below mentioned solution

//Load the library
$this->load->library('html2pdf');

//Set folder to save PDF to
$this->html2pdf->folder('./uploads/pdfs/');

//Set the filename to save/download as
$this->html2pdf->filename('new.pdf');

//Set the paper defaults
$this->html2pdf->paper('a4', 'portrait');

for Sending this particular file in email.

$this->load->library('email');

$this->email->from('your@example.com', 'Your Name');
$this->email->to('someone@example.com'); 

$this->email->subject('Email PDF Test');
$this->email->message('Testing the email a freshly created PDF');   

$this->email->attach($path_to_pdf_file);

$this->email->send();

Let me know if it not work.