Php 如何将网页中的数据转换和下载为PDF
我正在使用PHP Codeigniter开发一个web应用程序,我需要一个代码来显示数据并将其从网页下载为PDF格式。下载并将其解压缩到Php 如何将网页中的数据转换和下载为PDF,php,codeigniter,pdf,Php,Codeigniter,Pdf,我正在使用PHP Codeigniter开发一个web应用程序,我需要一个代码来显示数据并将其从网页下载为PDF格式。下载并将其解压缩到应用程序/第三方/文件夹 在application/libraries/中创建一个新文件,将其命名为M_pdf.php 在M_pdf.php文件中 <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); include_once APPPATH.'/third_pa
应用程序/第三方/
文件夹
在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);
}
}
你自己尝试了什么?StackOverflow不是一个编程服务。你想动态生成PDF,或者只是想下载已经存储的PDF。我的数据库中有数据,我必须使用这些数据创建PDF文件并下载。然后你应该用谷歌搜索如何在PHP中创建PDF(有库和示例),尝试自己创建,然后,如果你被卡住了,回到这里,给我们看看你的代码和你被卡住的地方。我们需要看到一些努力。
<?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");
}