close

TCPDF

官網:https://tcpdf.org/

PHP 框架 使用 Codeigniter

 

其實跟之前的PHPExcel很像,阿哈哈哈,我根本就是照那邊弄來的的

功能簡述:想要在網頁上,點擊一個按鈕就可以下載pdf

1. 下載 TCPDF,放在third_party底下

2. 在libraies 加入 pdf.php

<?php

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

 require_once APPPATH . "/third_party/TCPDF/TCPDF.php";

 class Pdf extends TCPDF {

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

 

 

js / 點擊事件

$("#create_report").click(function () {

 window.location.href = 'controller/create_report';

});

 

 

php / 產生report function 

public function create_report() {

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

 $pdf = new Pdf('P', 'mm', 'A4', true, 'UTF-8', false);
 $pdf->SetCreator(PDF_CREATOR);

 $pdf->AddPage();
 $html = "<h1>I'm Kai</h1>";
 $pdf->writeHTML($html, true, false, true, false, '');
 $pdf->Output();

}

arrow
arrow
    文章標籤
    TCPDF PHP codeigniter 匯出
    全站熱搜

    Kaikai凱開 發表在 痞客邦 留言(0) 人氣()