Reputation: 313
I have a HTML form data getting from database. I use PHP framework codeigniter . we want generate a PDF file from this HTML form data. tell me how to do.
Upvotes: 0
Views: 12877
Reputation:
You can also use mPDF Library to create pdf in codeignator. create the mpdf.php file. After that put it into the CodeIgniter library directory.
copy this code to mpdf.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 = "'c', 'A4-L'")
{
$this->param =$param;
$this->pdf = new mPDF($this->param);
}
}
Then, download mPDF Library from github or mpdf website.After downloading, Extract it and put the mpdf folder into CodeIgniter third_party directory.Then, Open your controller(here,i am using Welcome controller) ,create a method on that controller as following
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Welcome extends CI_Controller {
function my_mPDF(){
$filename = time()."_order.pdf";
$html = $this->load->view('unpaid_voucher',$data,true);
// unpaid_voucher is unpaid_voucher.php file in view directory and $data variable has infor mation that you want to render on view.
$this->load->library('M_pdf');
$this->m_pdf->pdf->WriteHTML($html);
//download it D save F.
$this->m_pdf->pdf->Output("./uploads/".$filename, "F");
}
}
?>
Here, my_ mPDF function of Welcome controller will generate pdf file of common/template view file.
It’s done. I hope it will help you.
Upvotes: 0
Reputation: 1005
Look at DomPDF https://github.com/dompdf/dompdf Examples: http://pxd.me/dompdf/www/examples.php
By the way, on my project I use Zend Framework and ZendParadoxPDF to ge generate pdf. But it requires Java, so ASAP I'll redevelop it using DomPDF.
Upvotes: 0
Reputation: 1547
You may wanna look at html2Pdf. It is a php class based on FPDF and it allows you to create PDF file from HTML. So just format your text using html and then create its pdf. Its very flexible and give greate control.
Or You can also look at this: Convert HTML + CSS to PDF with PHP?
Upvotes: 1