2016-07-25 56 views
-1

我正在开发一个使用PHP Codeigniter的Web应用程序,我想要一个代码来显示和从网页下载数据到PDF格式。如何将网页中的数据转换并下载到PDF

+5

你试了一下自己? StackOverflow不是一个编程服务。 –

+0

您想要动态生成PDF或只想下载已存储的PDF。 –

+0

我在我的数据库中有数据,使用该数据我必须创建pdf文件并下载它。 –

回答

0

下载mPDF并将其解压到文件夹application/third_party/

创建application/libraries/名称的新文件,它M_pdf.php

M_pdf.php文件

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

include_once APPPATH.'/third_party/mpdf/mpdf.php'; 

class M_pdf { 

    public $param; 
    public $pdf; 

    public function __construct($param = '"en-GB-x","A4","","",10,10,10,10,6,3') 
    { 
     $this->param =$param; 
     $this->pdf = new mPDF($this->param); 
    } 
} 

CI中那么成功整合MPDF。

如何使用 负荷控制器的MPDF库如下控制器,

<?php 
defined('BASEPATH') OR exit('No direct script access allowed'); 

class Cont_letter_pdf extends CI_Controller { 

    public function __construct() { 
     parent::__construct(); 

     $this->load->library('m_pdf'); //load mPDF library  
    } 

    public function pdf_download() 
    { 
     $data = []; 
     //load the view and saved it into $html variable 
     $html=$this->load->view('welcome_message', $data, true); 

     //this the the PDF filename that user will get to download 
     $pdfFilePath = "output_pdf_name.pdf"; 

     //load mPDF library 
     $this->load->library('m_pdf'); 

     //generate the PDF from the given html 
     $this->m_pdf->pdf->WriteHTML($html); 

     //download it. 
     $this->m_pdf->pdf->Output($pdfFilePath, "D"); 

    } 

我学习这从以下网址。您也可以从这里查看教程。

https://arjunphp.com/generating-a-pdf-in-codeigniter-using-mpdf/

相关问题