2012-05-13 91 views
0

我是Codeigniter的新手。我試圖將gridview數據導出爲pdf文件,我使用的是mpdf庫。該庫解包並放置\ system \ helpers,然後創建一個pdfexport_helper.php,它放在\ system \ helpers上。 pdfexport_helper.php這個文件如何在php中使用Codeigniter將gridview數據導出爲pdf文件

<?php 

if (! function_exists('exportMeAsMPDF')) 
{ 
      function exportMeAsMPDF($htmView,$fileName) { 

         $CI =& get_instance(); 
         $CI->load->library('MPDF54/mpdf.php'); 
         // $CI->mpdf=new mPDF('c','A4','','',32,25,27,25,16,13); 
         $CI->mpdf->AliasNbPages('[pagetotal]'); 
         $CI->mpdf->SetHTMLHeader('{PAGENO}/{nb}', '1',true); 
         $CI->mpdf->SetDisplayMode('fullpage'); 
         $CI->mpdf->pagenumPrefix = 'Page number '; 
         $CI->mpdf->pagenumSuffix = ' - '; 
         $CII->mpdf->nbpgPrefix = ' out of '; 
         $CI->mpdf->nbpgSuffix = ' pages'; 
         $CI->mpdf->SetHeader('{PAGENO}{nbpg}'); 
         $CI->mpdf = new mPDF('', 'A4', 0, '', 12, 12, 10, 10, 5, 5); 
         $style = base_url().'/source/template/css/stylesheet.css'; 
         $stylesheet = file_get_contents($style); 
         $CI->mpdf->WriteHTML($stylesheet,1);      
         $CI->mpdf->WriteHTML($htmView,2);      
         $CI->mpdf->Output('mpdf.pdf','I'); 
      } 
} 

和我CONTROLER包含

function pdf() 
    { 
     $this->load->helper('pdfexport_helper.php'); 
     $urlid = $this->uri->segment('3'); 
     if($urlid == "export") 
     { 

      $data['pageTitle'] = "Annual Report"; 
      $data['htmView'] = $this->load->view('site_view',$data,TRUE); 
      $templateView = $this->load->view('../template_export',$data,TRUE); 
      exportMeAsMPDF($templateView,$data['filename']);  

     } 
    } 

和我的看法是

<html> 
    <head> 
     <title><?=$page_title?></title> 
    </head> 
    <body> 
    <p align="right"> <a href="<?php echo base_url();?>index.php/site/pdf" style="text-align:right">Export to PDF</a></p> 

    <table border="1"> 
     <?php foreach($result as $row):?> 

     <tr> 
     <td><a href=""><?=$row->id?></a></td> 
     <td><p><?=$row->firstname?></p></td> 
     <td><p><?=$row->lastname?></p></td> 
     <td><p><?=$row->email?></p></td> 
     <td><a href="<?php echo base_url();?>index.php/site/update">Update</a></td> 
     <td><a href="">Delete</a></td>  

     <?php endforeach;?> 
     </tr> 
     </table> 
    </body> 
</html> 

當我點擊導出PDF它顯示空白頁。

任何人都可以幫助我。提前感謝。

回答

相關問題