douxi7219 2012-05-13 05:14
浏览 25
已采纳

如何使用Codeigniter将gridview数据导出到php中的pdf文件[关闭]

I am new to the Codeigniter. I am tryng to export gridview data to pdf file ,I am using mpdf library .That library i unpack and place the \system\helpers and i created the a pdfexport_helper.php ,it placed on \system\helpers. pdfexport_helper.php this file

<?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');
            }
}

and my controler contains

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']);     

        }
    }

and my view is

<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>

when i click the Export the pdf it showing empty page.

Can any one help me .Thanks in advance.

  • 写回答

1条回答 默认 最新

  • drxnfdx798517235 2012-05-13 10:00
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化