2016-10-22 123 views

回答

2

下载库从here

图书馆explanation

后下载解压文件夹,你有,你会发现两个文件,即class.ezpdf.php/cezpdf.php和class.pdf.php。现在将这两个.php文件放入应用程序/库中。为了使这些工作在CI中工作,您将不得不在cezpdf.php/class.ezpdf.php中进行修改。修改是在包括语句来完成:

include_once(APPPATH . 'libraries/class.pdf.php'); 

现在去你的控制器文件夹,并有使一个新的文件名generate.php和pdf_helper.php。

pdf_helper.php:

<?php 

function prep_pdf($orientation = 'portrait') 
{ 
    $CI = & get_instance(); 

    $CI->cezpdf->selectFont(base_url() . '/fonts');  

    $all = $CI->cezpdf->openObject(); 
    $CI->cezpdf->saveState(); 
    $CI->cezpdf->setStrokeColor(0,0,0,1); 
    if($orientation == 'portrait') { 
     $CI->cezpdf->ezSetMargins(50,70,50,50); 
     $CI->cezpdf->ezStartPageNumbers(500,28,8,'','{PAGENUM}',1); 
     $CI->cezpdf->line(20,40,578,40); 
     $CI->cezpdf->addText(50,32,8,'Printed on ' . date('m/d/Y h:i:s a')); 
     $CI->cezpdf->addText(50,22,8,'PDF Tutorial'); 
    } 
    else { 
     $CI->cezpdf->ezStartPageNumbers(750,28,8,'','{PAGENUM}',1); 
     $CI->cezpdf->line(20,40,800,40); 
     $CI->cezpdf->addText(50,32,8,'Printed on ' . date('m/d/Y h:i:s a')); 
     $CI->cezpdf->addText(50,22,8,'PDF Tutorial'); 
    } 
    $CI->cezpdf->restoreState(); 
    $CI->cezpdf->closeObject(); 
    $CI->cezpdf->addObject($all,'all'); 
} 

?> 

generate.php:

<?php 

class Generate extends CI_Controller 
{ 

    function Generate() 
    { 
     parent::__construct(); 
     $this->load->database(); 
     $this->load->helper('url'); 
    } 


    function create() 
    { 

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

     $this->cezpdf->ezText('PDF REPORT OF LOGIN TABLE', 12, array('justification' => 'center')); 
     $this->cezpdf->ezSetDy(-10); 
       $i=1; 
       $content=""; 

       $fname=""; 
       $query = $this->db->query('SELECT * FROM table_name'); 
       $num = $query->num_fields(); 
       $farr=array(); 

       while($i <= $num){ 
        $test = $i; 
        $value = $this->input->post($test); 

        if($value != ''){ 
          $fname= $fname." ".$value; 
          array_push($farr, $value); 

         } 
        $i++; 
       } 

       $fname = trim($fname); 

       $fname=str_replace(' ', ',', $fname); 
       $this->db->select($fname); 
       $query = $this->db->get('table_name'); 
       $result = $query->result(); 

       foreach ($farr as $j) 
       { 

        $content= strtoupper($j)."\n\n"; 
        foreach($result as $res){ 
         $content = $content.$res->$j."\n"; 
        } 

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

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

    } 

在我们上面做,第一件事就是加载将R & OS库使用。接下来我们使用ezText()函数为我们的文档创建一个标题。这个函数把它将显示的文本作为第一个参数,文本的大小和一个可选的附加配置选项数组。

在白人的脚步之后,我们将文档的其余内容放在名为$ content的变量中,并再次使用ezText()函数将其添加到文档中。最后,我们使用ezStream()函数创建文档,该函数实际创建文档并将其发送给提示用户查看/下载生成的PDF文档的用户。