HTML在笨PDF转换

问题描述 投票:0回答:1

控制器:功能income_reports()

 public function income_reports(){

    if(isset($_POST["search"])) {
    $from=$this->input->post('from_date');
    $to=$this->input->post('to_date');
    $this->load->model("Home_model");
    $data['view_report']=$this->Home_model->income_report($from,$to);
    $data['cat_result']=$this->Home_model->add_cat();
    $pdfFilePath = "output_pdf_name.pdf";
    $this->load->library('m_pdf');
    $html = $this->load->view('income_reports',$data,true);
    $this->m_pdf->pdf->WriteHTML($html);
    $this->m_pdf->pdf->Output($pdfFilePath, "D");

  }

 }

视图:

 <!DOCTYPE html>
 <html>
  <head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title> Income |Report</title>
  <!-- Tell the browser to be responsive to screen width -->
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">

   </head>
    <div class="wrapper" >
     <!-- Main content -->
     <section class="invoice">

        <!-- Table row -->
        <div class="row">
           <div class="col-xs-12 table-responsive">
              <table class="table-border" cellspacing="50">
                 <thead>
                    <tr>
                      <th>#</th>
                      <th>Date</th>
                      <th>Category</th>
                      <th>Description</th>
                      <th>Income Amount</th>
                    </tr>
                 </thead>
                 <tbody>
                        <?php
                   $total_sum=0;
                                  if($view_report->num_rows() > 0)
                         {
                              $i=1;
                               foreach($view_report->result() as $row)
                                {
                           ?>
                    <tr>
                      <td><?php echo $i++;?></td>
                       <td><?php echo $row->date;?></td>
                        <td><?php echo $row->cat_name;?></td>
                        <td><?php echo $row->description;?></td>
                        <td><?php echo $row->inc_amount;?></td>
                    </tr>
                    <?php
                     $total_sum+=$row->inc_amount;
                             }

                          }
                          else
                           {

                           ?>

                                   <tr><td>Not Found</td></tr>

                           <?php
                          }
                           ?>
                 </tbody>
              </table>
              <div>

            <h4 style="color: green; padding-left: 500px;">Total : ₹<?php echo $total_sum ?> !</h4>
          </div>
           </div>
           <!-- /.col -->
        </div>

        <!-- /.row -->
     </section>
     <!-- /.content -->
     </div>
     <!-- ./wrapper -->
    </body>
   </html>

在这段代码中我创建了一个视图文件有名称income_reports.php,现在我想这些问题导出为PDF格式,这个我使用mpdf CodeIgniter在那里我有在第三方负载M_pdf.php图书馆和pdf,但它不工作就说明我的错误。

所以,我怎样才能解决这个问题?请帮我。

错误:1)

一个PHP错误遇到严重性:通知消息:未定义的属性:m_pdf :: $ PDF文件名:控制器/ Home.php行号:156

2)

未捕获的异常时遇到类型:错误消息:调用一个成员函数的WriteHTML()上的空文件名:C:\ XAMPP \ htdocs中\ income_expence_manage \应用\控制器\ Home.php行号:156

谢谢

javascript php codeigniter
1个回答
0
投票

尝试这个 :

一,应用/库/ M_pdf.php:

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class M_pdf {

    function m_pdf()
    {
        $CI = & get_instance();
        log_message('Debug', 'mPDF class is loaded.');
    }

    function load($param=NULL)
    {
        include_once APPPATH.'/third_party/mpdf/mpdf.php';

        if ($params == NULL)
        {
            $param = '"en-GB-x","A4","","",10,10,10,10,6,3';                
        }

        //return new mPDF($param);
        return new mPDF();
    }
}
?>

2.复印MPDF文件夹应用程序/ THIRD_PARTY /

3.Controller:

$html = $this->load->view('filename',$data,true);
$pdfFilePath = 'path/filename';
$pdf = $this->m_pdf->load();
$pdf->AddPage('','','','','',5,5,5,5,10,10); //set margin
$pdf->WriteHTML($html,2);
ob_clean();
$pdf->Output($pdfFilePath, "F");
© www.soinside.com 2019 - 2024. All rights reserved.